Azure App Service - write to filesystem - ASP.NET web application

后端 未结 2 1938
渐次进展
渐次进展 2021-01-21 10:12

I have an ASP.NET web application, created in Visual Studio 2017.

In the application there is a form, where the users can upload files. When files are uploaded, I proces

相关标签:
2条回答
  • 2021-01-21 10:30

    You should never use absolute paths on server components. Try something like this for instance

    var folder = Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData);
    var filePath = Path.Combine(folder, Request.Files["file"]);
    
    0 讨论(0)
  • 2021-01-21 10:53

    Use %TEMP%, which on Azure App Service (Windows) resolves to d:\local. That's the local machine disk, not network storage, so significantly faster. It gets wiped on app restart so code accordingly.

    var tempDirectoryPath = Environment.GetEnvironmentVariable("TEMP");
    var filePath = Path.Combine(tempDirectoryPath, Request.Files["file"]);
    

    If you want durability use Blob Storage instead.

    0 讨论(0)
提交回复
热议问题