1
votes

I'm developing a web site with backend web api ASP.NET CORE 2.1 and frontend angular 6.

In this site I'm integrating upload of large files through web api with microsoft.azure.storage 9.3.2. I'm doing this chunking by blocks, and sending them from FE to an endpoint. Inside I do the following logic:

  var container = CloudStorageAccount.Parse(key).CreateCloudBlobClient().GetContainerReference(containerName);
  var result = await container.CreateIfNotExistsAsync();
  if (result)
  {
    await container.SetPermissionsAsync(new BlobContainerPermissions
    {
      PublicAccess = BlobContainerPublicAccessType.Blob
    });
  }
  BlockBlob = container.GetBlockBlobReference(blobName);

   await fileUploadSession.BlockBlob.PutBlockAsync(block.BlockId, chunkStream, null);

And I have an exception here that says " The value for one of the HTTP headers is not in the correct format."

the stackTrace is:

at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.d__4`1.MoveNext() in C:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\WindowsRuntime\Core\Executor\Executor.cs:line 316 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.d__62.MoveNext() in C:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\WindowsRuntime\Blob\CloudBlockBlob.cs:line 1020 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at vidiwin2Api.Controllers.VideosController.d__18.MoveNext() in D:\repos\vidiwin2api\vidiwin2Api\Controllers\VideosController.cs:line 469

The most amazing is that I had the same functionality in an older version, with BE web api on Framework 4.6 and microsoft.azure.storage 6.0.0, and this works!!

I have tested all kind of params in PutBlockAsync and allways the same exception.

Can anyone helps me please?

1

1 Answers

5
votes

I had the same error because i forgot to reset the stream position to 0 before calling PutBlockAsync(). Try

chunkStream.Position = 0;
await fileUploadSession.BlockBlob.PutBlockAsync(block.BlockId, chunkStream, null);

Otherwise inspect the ExtendedErrorInformation property on the Exception. There you will find additional information about the wrong HTTP header.