2

Problem

I am trying to generate Pdf and create MemoryStream object and trying to upload that stream to azure Blob Storage. I am already tried the below code so far but the blob is not uploaded to azure and also what is the name of that blob which I upload using stream method of azure sdk

Code

var memoryStream = new MemoryStream(byteArray, 0, byteArray.Length);
var cred = new StorageCredentials("foo", "key");
var account = new CloudStorageAccount(cred, true);
var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("container");
CloudBlockBlob sourceBlob = container.GetBlockBlobReference("foo/bar");
var attachment =  sourceBlob.UploadFromStreamAsync(memoryStream);
1
  • 1
    First thing that stands out is the missing await on the call to UploadFromStreamAsync. Commented Jul 21, 2018 at 18:43

1 Answer 1

3

As @Kirk has said, use await sourceBlob.UploadFromStreamAsync(memoryStream); instead of var attachment = sourceBlob.UploadFromStreamAsync(memoryStream); Or your code will exit before upload is finished.

Note that your method should change to public async Task methodname(), you will see related tip shown by VS.

Some references for you

And see container.GetBlockBlobReference("blobname"); the string you use to get blob reference is the name of blob uploaded.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.