Azure storage: Uploaded files with size zero bytes

后端 未结 2 2021
野性不改
野性不改 2021-01-17 07:14

When I upload an image file to a blob, the image is uploaded apparently successfully (no errors). When I go to cloud storage studio, the file is there, but with a size of 0

相关标签:
2条回答
  • 2021-01-17 07:58

    The Position property of the InputStream of the HttpPostedFileBase had the same value as the Length property (probably because I had another file previous to this one - stupid I think!).

    All I had to do was to set the Position property back to 0 (zero)!

    I hope this helps somebody in the future.

    0 讨论(0)
  • 2021-01-17 07:59

    Thanks Fabio for bringing this up and solving your own question. I just want to add code to whatever you have said. Your suggestion worked perfectly for me.

            var memoryStream = new MemoryStream();
    
            // "upload" is the object returned by fine uploader
            upload.InputStream.CopyTo(memoryStream);
            memoryStream.ToArray();
    
    // After copying the contents to stream, initialize it's position
    // back to zeroth location
    
            memoryStream.Seek(0, SeekOrigin.Begin);
    

    And now you are ready to upload memoryStream using:

    blockBlob.UploadFromStream(memoryStream);
    
    0 讨论(0)
提交回复
热议问题