【问题标题】:CLoudBLob Storage Fetch Properties (404 Error)CLoudBLob 存储提取属性(404 错误)
【发布时间】: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


    【解决方案1】:

    如果URI 代表一个blob URI,那么您将不得不使用CloudBlob 构造函数来创建一个实例。所以你的代码是:

    CloudBlob blob = new CloudBlob(new Uri(url), blobClient);
    

    您收到此错误的原因是因为GetBlobReference 方法需要 blob 的名称,而不是完整的 URI。

    【讨论】:

      猜你喜欢
      • 2021-04-16
      • 2021-09-21
      • 1970-01-01
      • 1970-01-01
      • 2021-07-02
      • 2014-07-01
      • 1970-01-01
      • 2019-11-30
      • 1970-01-01
      相关资源
      最近更新 更多