C# CLoudBLob存储获取属性(404错误)
我正在尝试使用以下代码通过URL获取文件:C# CLoudBLob存储获取属性(404错误),c#,asp.net,.net,azure,blob,C#,Asp.net,.net,Azure,Blob,我正在尝试使用以下代码通过URL获取文件: public async Task<string> GetInlineImageSrcAsync(string url) { //Instance objects needed to store the files var storageAccount = new CloudStorageAccount(new StorageCredentials(AccountName, Key), true);
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;
}
公共异步任务GetInlineImageSrcAsync(字符串url)
{
//存储文件所需的实例对象
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 filebytellength=cloudBlob.Properties.Length;
byte[]bytes=新字节[filebytellength];
for(int i=0;iStackTrace=“在Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand`1 cmd,IRetryPolicy策略,OperationContext OperationContext)中,位于c:\Program Files(x86)中\Jenkins\workspace\release\u dotnet\u master\Lib\ClassLibraryCommon\Core\Exec…如果
URI
表示blob URI,则必须使用构造函数创建实例。因此,您的代码为:
CloudBlob blob = new CloudBlob(new Uri(url), blobClient);
出现此错误的原因是该方法需要blob的名称,而不是完整的URI