Azure应用服务-写入文件系统-ASP.NET Web应用程序 [英] Azure App Service - write to filesystem - ASP.NET web application

查看:90
本文介绍了Azure应用服务-写入文件系统-ASP.NET Web应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Visual Studio 2017中创建的ASP.NET Web应用程序.

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 process them and I save them on the filesystem:

var photo = Request.Files["file"];
photo.SaveAs("D:\\home");

一切在本地都能正常运行,但是当我在Azure App Services上部署应用程序时,一切都无法正常工作.

Everything works perfect locally, but it's not working when I deploy the App on Azure App Services.

我在Azure上读到了该路径

I read that, on Azure, the path

D:\home

应该是可写的.

但是当我尝试代码时,出现此错误:

But when I try the code I get this error:

Access to the path 'd:\home\test_image.JPG' is denied.

推荐答案

使用%TEMP%,它在Azure App Service(Windows)上解析为d:\local.那是本地计算机磁盘,而不是网络存储,因此速度大大提高.在应用重新启动时会被清除,因此相应地进行编码.

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"]);

如果要持久耐用,请改用Blob存储.

If you want durability use Blob Storage instead.

这篇关于Azure应用服务-写入文件系统-ASP.NET Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆