【发布时间】:2020-03-16 00:16:37
【问题描述】:
我正在尝试使用以下代码通过 URL 获取文件:
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;
}
但是在 fetchproperties 方法中,它总是抛出异常 (404)。
当我进行远程调试时,我可以看到 cloudBlob 实际上不为空,这意味着找到了文件!
堆栈跟踪
StackTrace = " 在 Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd, IRetryPolicy 策略, OperationContext operationContext) 在 c:\Program Files (x86)\Jenkins\workspace\release_dotnet_master \Lib\ClassLibraryCommon\Core\Exec...
【问题讨论】:
标签: c# asp.net .net azure blob