【问题标题】:Azure SDK - NodeJS - Invalid MD5 hashes on re-upload of blobAzure SDK - NodeJS - 重新上传 Blob 时的 MD5 哈希值无效
【发布时间】:2016-05-10 04:20:04
【问题描述】:

我正在编写一个脚本,该脚本使用适用于 NodeJS 的 Azure SDK 下载 Blob 列表,并将 Blob 重新上传到不同的存储容器。

var service = azure.createBlobService();

// download file
service.getBlobToLocalFile(fromContainer, blob, localBlob, function(err, resp){ // resp here contains the MD5 hash

    // re-upload file specifying hash
    service.createBlockBlobFromLocalFile(toContainer, blob, localBlob, {contentMD5: resp.contentMD5}, function(error){}); // error here contains MD5 mis-match error
}); 

一些 blob(并非全部)在上传时抛出错误,指出来自 blob 的 MD5 哈希不正确,即使我从 getBlob 操作传递 MD5 哈希:

Error: The MD5 value specified in the request did not match with the MD5 value calculated by the server.

此错误仅发生在某些 blob 上。其他 blob 上传成功,表示 MD5 哈希正确。

我的问题分为两部分:

  1. 如果我在下载 blob 时传递从 Azure 接收的值,MD5 哈希怎么可能不正确?
  2. Azure 如何计算其 MD5 哈希?我无法重新计算哈希,因为他们正在对 MD5 哈希进行一些其他加密/操作以将其置于不同的格式,并且我找不到关于他们如何编码 MD5 哈希的文档。这是来自 Azure 的示例“MD5”哈希,显然不是 MD5 格式:

    8kz7pLKnPFlF5G6gy+0rrg==

谢谢。

【问题讨论】:

    标签: node.js azure md5 azure-storage


    【解决方案1】:

    你在项目中使用了哪个版本的Azure-storage-node模块,根据GitHub上https://github.com/Azure/azure-storage-node/issues/78的问题,如果sdk版本低于0.6.0可能会出现这个问题,你可以先检查sdk的版本。

    我们可以在 GitHub 存储库上找到 calculateMD5 function。这表明它将利用 blob 文件的内容在md5 中创建哈希对象,并在base64 中编码为contentMD5 的返回值。

    所以根据 Azure blob storage sdk 中计算 MD5 密钥的方法,您可以检查本地上传到 Azure Storage 的文件是否与从 Storage 下载的文件相同。

    【讨论】:

    • 升级到最新的 Azure SDK 解决了这个问题。我没想过这样做。谢谢!!
    【解决方案2】:

    我在 Windows 下使用 Azure SDK for NodeJS 5.4.1 测试了您的代码。它运作良好。没有出现 MD5 问题。我认为最好更换新版本的 NodeJs Server。以下是 Node.js 服务器的一些链接:

    Windows 安装:http://go.microsoft.com/fwlink/?linkid=254279&clcid=0x409

    linux 安装:http://go.microsoft.com/fwlink/?linkid=253472&clcid=0x409

    mac 安装:http://go.microsoft.com/fwlink/?linkid=253471&clcid=0x409

    【讨论】:

    • 感谢您的帮助。这确实是旧版本的 Azure SDK 的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-08
    • 2016-12-26
    • 1970-01-01
    • 2012-08-17
    • 2015-07-12
    • 2015-09-19
    相关资源
    最近更新 更多