Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

HTTP Error 502.3 - Bad Gateway using Azure Blob PutBlockAsync

$
0
0

Dear Sirs.

I'm Trying to upload large file to Azure BLOB it works on small files but in large file I got error 

Module: AspNetCoreModule
Notification: ExecuteRequestHandler
Handler: aspNetCore
Error Code: 0x80072ee2

here is a code

public async Task<IActionResult> UploadBloblByChanks(IFormFile sourcefile)

{
var sourcefilename1 =
ContentDispositionHeaderValue
.Parse(sourcefile.ContentDisposition)
.FileName
.Trim('"');

var outputfilename = Path.GetFileName(sourcefilename1);
long totalBytes = sourcefile.Length;

string filename = ContentDispositionHeaderValue.Parse(sourcefile.ContentDisposition).FileName.Trim('"');
byte[] buffer = new byte[16 * 1024];

CloudBlobContainer containerrefernece = _mycloudclient.GetContainerReference(_containername);
CloudBlockBlob blockBlob = containerrefernece.GetBlockBlobReference(outputfilename);
List<string> blockIds = new List<string>();
int blockIdcounter = 0;

using (Stream input = sourcefile.OpenReadStream())
{
long totalReadBytes = 0;
int readBytes;

while ((readBytes = input.Read(buffer, 0, buffer.Length)) > 0)
{
blockIdcounter++;
BlobRequestOptions requestoptions = new BlobRequestOptions { MaximumExecutionTime = new TimeSpan(0, 10, 0), ServerTimeout = new TimeSpan(0, 10, 0) };
string currentblockId = blockIdcounter.ToString("d4");
using (MemoryStream ms = new MemoryStream(buffer))
{
await blockBlob.PutBlockAsync(currentblockId, ms, null, null, requestoptions, null);
}
blockIds.Add(currentblockId);

totalReadBytes += readBytes;
}
}

BlobRequestOptions requestoptions2 = new BlobRequestOptions { MaximumExecutionTime = new TimeSpan(0, 20, 0), ServerTimeout = new TimeSpan(0, 20, 0) };

await blockBlob.PutBlockListAsync(blockIds,null, requestoptions2, null);

return RedirectToAction("Details", "CodexUpdateFiles", new { id = outputfilename });

}


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>