Download file from azure blob storage c# mvc






















Show 13 more comments. AGuyCalledGerald 7, 16 16 gold badges 67 67 silver badges bronze badges. Luchian Luchian 2 2 silver badges 3 3 bronze badges. How exactly would you do that? Sounds interesting. An example would be nice i mean how to store it in the cache, not generating the excel file. How scalable is this though? If a user is downloading several large reports?

SaveXlsx stream ; stream. Andy S Andy S 1 1 silver badge 2 2 bronze badges. I had a similar approach. WriteDataTableToExcel dt, ". Create, FileAccess. Write ; exportData. WriteTo file ; file. Result as FilePathResult.

Elvin Acevedo Elvin Acevedo 99 1 1 silver badge 6 6 bronze badges. Chris Andrews 33 6 6 bronze badges. Niclas Niclas 3 3 silver badges 9 9 bronze badges.

Nichlas I had started using TempData also, your answer prompted me to update mine to reflect this! SerializeObject dbcontext. DeserializeObject Emplist, typeof DataTable ; dt RAO G. RAO 91 1 1 silver badge 3 3 bronze badges. ToArray , System. Octet, "TeamMembers. Set handle, memoryStream. SetSlidingExpiration TimeSpan. Now there is some extra code for setting up MemoryCache Memory; namespace MySolution. AddDistributedMemoryCache ;. NewGuid ; HttpContext. Insert guid.

ToString , input, null, DateTime. GetBlobClient fileName ; Console. OpenRead localFilePath ; await blobClient. Close ;. WriteLine "Listing blobs BlobItem blobItem in containerClient. Andrew Halil. Post Views: If you do it from your local machine, it may take up to 10 minutes for every records.

First of all, how do you identify the first and next …. When you have 1 million records, here is the solution. The above method will give you the List of List count and your first index in your startingIndex and the list last index in your EndIndex so, use these 2 indexes to fetch the records from the main table using below query.

Now we are going to upload this binary information to blob storage in Azure. You should encode the filename and if you really want to prevent unauthorized types, you could go even further by adding some checking to read the first few bytes of the stream and verify the type. If you want to get or save the filesize, you can check the position of the stream after uploading it to blob storage.

Do this instead of trying to get the length of the stream beforehand. The Uri that is generated as part of the blob will include an access token at the end. There are multiple upload methods available, but make sure you choose one that has an input of a Stream, and use the section.

Body stream to send the upload. This may be the most important instruction. Compare your profiling results to that of a known memory-eating method, such as an IFormFile. Beware that different versions of the Azure Blob Storage library may perform differently.

And different implementations may perform differently also! Here were some of my results. To do this simple profiling, I used PostMan to upload multiple files of around 20MB in several requests. By using a collection, or by opening multiple tabs, you can submit multiple requests at a time to see how the memory of the application is consumed. First, using an IFormFile. You can see the memory usage increases rapidly for each request using this method. Next, using the latest version v12 of the Azure Blob Storage libraries and a Stream upload method.

Although BlobStorageClient is the latest way to interact with blob storage, when I look at the memory snapshots of this operation it has internal buffers at least, at the time of this writing that cause it to not perform too well when used in this way.

But, using almost identical code and the previous library version that uses CloudBlockBlob instead of BlobClient, we can see a much better memory performance. For your reference, here is a version of the upload service methods from that last profiling result:. NET stack development experience. She started her career in circuitry design and automated test systems before becoming a software consultant.

But her true passion has always been for building real, useful, elegant software. Hi Rachel, this is an awesome article. Thank you. Hi Teddy, thank you for the comment!



0コメント

  • 1000 / 1000