如何使用邮递员将图像上传到 azure blob 存储

Man*_*ari 3 rest blob binaryfiles azure azure-storage-blobs

我一直在尝试使用邮递员将图像上传到我的 blob 容器文件夹这里是Azure 存储服务 REST API 的授权链接用于生成签名并在正文中附加文件名文件字段。

var key = "[Storage account key]";
var strTime = (new Date()).toUTCString();
var strToSign = 'PUT\n\nimage/jpeg; charset=UTF-8\n\nx-ms-date:' + strTime + '\nx-ms-meta-m1:v1\nx-ms-meta-m2:v2\n/colony7/folder-customer-profilepic/Home - explorar.jpg';
var secret = CryptoJS.enc.Base64.parse(key);
var hash = CryptoJS.HmacSHA256(strToSign, secret);
var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
var auth = "SharedKey colony7:"+hashInBase64; 
Run Code Online (Sandbox Code Playgroud)

我使用过这些https://docs.microsoft.com/en-us/rest/api/storageservices/put-block,https://docs.microsoft.com/en-us/rest/api/storageservices/authentication-上面代码的 for-the-azure-storage-services 参考。

我也开启了cors。请分享有关如何使用邮递员将 jpg 或 png 图像上传到我的 blob 的解决方案。

提前致谢

Tom*_*SFT 5

如果我们想将图片上传到 azure 存储,请尝试使用Put blob API而不是 Put block API。

并尝试使用以下 strToSign。

"PUT\n\n\n{Content-Length}\n\n{Content-Type}\n\n\n\n\n\n\nx-ms-blob-type:BlockBlob\nx-ms-date:{date}\nx-ms-version:2015-12-11\n/accountname/container/blobname"   
Run Code Online (Sandbox Code Playgroud)

我在我这边进行了测试,它在现场正常工作。

标题:

在此处输入图片说明

身体:

在此处输入图片说明

注意:我们可以从文件大小中获取 Content-Length。

在此处输入图片说明


小智 5

  1. 方法:PUT

  2. 网址方案:

    (https://{{storageName}}.blob.core.windows.net/{{Container}}/{{ImageName.png}}?{{SAS Token}})
    
    Run Code Online (Sandbox Code Playgroud)
  3. 标题:

    "Content-Type": "image/png",
    "Content-Length": "{{size in Bytes}}",
    "x-ms-blob-type": "BlockBlob"
    
    Run Code Online (Sandbox Code Playgroud)
  4. Body:选择二进制添加图像(标题和URL中的图像名称应相同。)