Path inside an web app not a direct link

前端 未结 1 1648
执念已碎
执念已碎 2021-01-16 14:28

in my project i am currently using direct links, these store specific files that get uploaded to the server, these locations are all in the folder of the project (fileupload

相关标签:
1条回答
  • 2021-01-16 15:02

    Just make it externally configurable. There are various ways to achieve that.

    1. Set an environment variable during server startup.

      SET UPLOAD_LOCATION=C:\path\to\uploads
      

      It's available as follows:

      String uploadLocation = System.getenv("UPLOAD_LOCATION");
      
    2. Set a VM argument during server startup.

      -Dupload.location="C:\path\to\uploads"
      

      It's available as follows:

      String uploadLocation = System.getProperty("upload.location");
      
    3. Set it as a properties file entry.

      upload.location=C:\path\to\uploads
      

      It's available the usual Properties API way:

      String uploadLocation = properties.getProperty("upload.location");
      

      The location of the properties file itself is actually a whole question at its own, which is already answered here: Where to place and how to read configuration resource files in servlet based application?

    Either way, you can easily reference the files as follows:

    File some = new File(uploadLocation, "some.ext");
    
    0 讨论(0)
提交回复
热议问题