如何以及在何处存储部署在 Azure Web 应用程序中的 ASP.NET MVC 应用程序的文件

发布于 2025-01-13 02:23:12 字数 259 浏览 8 评论 0原文

我正在 .NET 4.7.2 上创建 ASP.NET MVC 应用程序。一项功能是用户上传文件,该文件暂时保存在本地文件夹 c:/ 中。提取数据后,文件将上传到 Azure 存储容器,临时文件夹将被清空。

我的问题是,当应用程序在 Azure Web App 中生产时,我应该将文件临时存储在哪里?部署到 Web 应用服务后。我收到错误,因为找不到路径。

请注意,将文件存储在 c:/临时文件夹中并不是必需的功能。只是不确定在上传到 Azure blob 之前如何处理该文件。

I am creating an ASP.NET MVC app on .NET 4.7.2. One functionality is that the user would uploads the file which saves the file in the local folder c:/temporarily. Once the data is extracted, the file would be uploaded to the Azure storage container and the temporary folder would be emptied.

My question is when the app is in production in Azure Web App where should I store the file temporarily? After deployment to Web App service. I am getting error because the path is not found.

Note that storing the file in c:/temporarily folder is not the required functionality. Just not sure how to handle the file prior to uploading to Azure blob.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我喜欢麦丽素 2025-01-20 02:23:12

我找到了答案, blob.Upload 是重载方法,它也接受文件流以及“文件路径+文件名”。因此,我没有使用临时存储文件,而是使用采用 filestream 参数的方法。

注意:下面的代码没有使用异步方法,但可以使用它。 blob.UploadAsync(..)

 public void Upload()
 {
   const string blobContainerName = "containername";              ;
    BlobServiceClient blobServiceClient = new BlobServiceClient(ConfigurationManager.AppSettings["StorageConnectionString"].ToString());

    blobContainer = blobServiceClient.GetBlobContainerClient(blobContainerName);
            blobContainer.CreateIfNotExists(PublicAccessType.Blob);
            BlobClient blob = blobContainer.GetBlobClient(fileName);

            //this uses the stream
            var check = blob.Upload(fileUpload.FileContent, true);
}

I found the answer, the blob.Upload is overloaded method which also takes the file stream as well as "file path+file name". So rather than to store the file temporarily I used the method that takes the filestream parameter.

Note: The code below does not use the async method but one can use it. blob.UploadAsync(..)

 public void Upload()
 {
   const string blobContainerName = "containername";              ;
    BlobServiceClient blobServiceClient = new BlobServiceClient(ConfigurationManager.AppSettings["StorageConnectionString"].ToString());

    blobContainer = blobServiceClient.GetBlobContainerClient(blobContainerName);
            blobContainer.CreateIfNotExists(PublicAccessType.Blob);
            BlobClient blob = blobContainer.GetBlobClient(fileName);

            //this uses the stream
            var check = blob.Upload(fileUpload.FileContent, true);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文