简体   繁体   中英

How and where to store a file from MVC application that is deployed in Azure webapp

I am creating a MVC.NET 4.7.2 app. 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.

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM