Azure container for storing containers for MemoryStream

I'm running around in circles trying to work out some code to load a file from a private Azure Storage container to a MemoryStream.

I still have it ...

StorageCredentials storageCredentials = new StorageCredentials(*my StorageAccountName*, *my StorageAccountAccessKey*);
CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true);

Uri blobUri = new Uri(featureFile.URL);
CloudBlockBlob blob = new CloudBlockBlob(blobUri);

MemoryStream mem = new MemoryStream();  
blob.DownloadToStream(mem);

      

These are errors on the last line with ...

The remote server returned an error: (404) Not found.

However, it will work without error if the container is not private.

Any help is greatly appreciated, thanks.

+3


source to share


1 answer


Please try the following code:

StorageCredentials storageCredentials = new StorageCredentials(*my StorageAccountName*, *my StorageAccountAccessKey*);
CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true);

Uri blobUri = new Uri(featureFile.URL);
CloudBlockBlob blob = new CloudBlockBlob(blobUri, storageCredentials);//added storageCredentials

MemoryStream mem = new MemoryStream();  
blob.DownloadToStream(mem);

      



Since the container has an Private

ACL, the request must be authenticated. Using the this

constructor CloudBlockBlob

will take care of that.

+8


source







All Articles