簡體   English   中英

C#在Azure上上傳大文件

[英]C# Upload a big file on Azure

我需要做一個上傳器。 所有文件都存儲在Azure雲中。 所以它是“ blob”文件。

上載器正在運行,但只能處理小文件,當客戶端嘗試上載大文件(例如,視頻> 50Mb)時,上傳會在3到4分鍾后停止。

<!-- language: c# -->
string connectionStr = ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString;
 CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionStr);
 CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
 // Retrieve a reference to a container. 
 string containerName = this.User.Login;
 containerName = containerName.ToLower();
 CloudBlobContainer container = blobClient.GetContainerReference(containerName);
 //Create the container if it doesn't already exist.
 container.CreateIfNotExists();
 BlobContainerPermissions blobContainerPermissions = new BlobContainerPermissions();
 blobContainerPermissions.PublicAccess = BlobContainerPublicAccessType.Blob;
 container.SetPermissions(blobContainerPermissions);
 // Retrieve reference to a blob named "myblob".
 CloudBlockBlob blockBlob = container.GetBlockBlobReference("fichiers-" + uploadFile.FileName.ToLower());
 // Create or overwrite the "myblob" blob with contents from a local file.
 using (var fileStream = uploadFile.InputStream)
 {
     blockBlob.UploadFromStream(uploadFile.InputStream);
 }

在嘗試解決此類問題之前,您應該調查一下行為。 使用Microsoft Azure進行此操作的一種方法是使用Fiddler。 確保您與Azure存儲帳戶的連接使用HTTP,而不是HTTPS,並僅執行對HTTP調用的跟蹤。 您應該看到您的有效載荷,並查看是否有錯誤消息返回。 您還可以推斷出重試邏輯(如果有),有效負載的大小等。

您的問題可能只是來自Microsoft Azure的一種限制形式,在這種情況下,您可能需要研究一種重試邏輯形式,或將有效負載分成較小的塊。

您很可能會用完內存:對於非常大的文件,在將它們存儲到blob存儲之前先在服務器上進行緩沖,這意味着您需要在服務器上有足夠的內存來保存文件。 一個更可靠的解決方案是將文件從瀏覽器直接上傳到Blob存儲,然后分塊上傳文件。 我發現本文和示例很有幫助,但是我確實必須在代碼中進行一些小的修復。

http://gauravmantri.com/2013/02/16/uploading-large-files-in-windows-azure-blob-storage-using-shared-access-signature-html-and-javascript/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM