Reputation: 34038
I am trying to get a file by URL using the following code:
public async Task<string> GetInlineImageSrcAsync(string url)
{
//Instance objects needed to store the files
var storageAccount = new CloudStorageAccount(new StorageCredentials(AccountName, Key), true);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer imagesContainer = blobClient.GetContainerReference(ProfilePicsContainer);
CloudBlob cloudBlob = imagesContainer.GetBlobReference(url);
cloudBlob.FetchAttributes();
long fileByteLength = cloudBlob.Properties.Length;
byte[] bytes = new byte[fileByteLength];
for (int i = 0; i < fileByteLength; i++)
{
bytes[i] = 0x20;
}
//var bytes = await _httpClient.GetByteArrayAsync(url);
var base64 = Convert.ToBase64String(bytes);
//var mimeType = "image/png";
// If mime types differ, try this
var mimeType = $"image/{ParseExtensionFromUrl(url)}";
var inlineImageSrc = $"data:{mimeType};base64,{base64}";
return inlineImageSrc;
}
However in the fetchproperties method, it always throws an exception (404).
WHen I do remote debugging I can see cloudBlob is actually not null, so that means the file is found!
stack trace
StackTrace = " at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master\Lib\ClassLibraryCommon\Core\Exec...
Upvotes: 0
Views: 292
Reputation: 136386
If the URI
represents a blob URI, then you will have to use CloudBlob
constructor to create an instance. So your code would be:
CloudBlob blob = new CloudBlob(new Uri(url), blobClient);
The reason you're getting this error is because GetBlobReference
method expects the name of the blob and not the full URI.
Upvotes: 1