dougang1605 2018-07-03 17:45
浏览 1939
已采纳

如何在Minio SDK中设置Content-MD5标头以上传到IBM Cloud Object Storage?

I am trying to set the Content-MD5 header when I use Minio Golang SDK to upload a file to S3. I can successfully upload files to AWS without setting Content-MD5, but uploading to IBM Cloud Object Storage fails with the following error:

ERR: Object write failed, reason: Missing required header for this request: Content-MD5

According to the Minio SDK,
https://docs.minio.io/docs/golang-client-api-reference#FPutObject
I use the UserMetadata field in minio.PutObjectOptions to set Content-MD5, but IBM Cloud Object Storage keeps complaining missing MD5, am I doing something wrong in the following code?

func (cloudIO *CloudIO) FWrite(name string) (n int, err error) {
    f, err := os.Open(name)
    if err != nil {
        log.Fatal(err)
    }
    defer f.Close()

    h := md5.New()
    if _, err := io.Copy(h, f); err != nil {
        log.Fatal(err)
    }

    bytesWritten, err := cloudIO.client.FPutObject(cloudIO.bucket, cloudIO.address,
        name,
        minio.PutObjectOptions{UserMetadata: map[string]string{"Content-MD5": hex.EncodeToString(h.Sum(nil))}})
    return int(bytesWritten), err
}
  • 写回答

1条回答 默认 最新

  • dongzhang5787 2018-07-06 18:17
    关注

    @pacalj If you look at AWS documentation for PutObject https://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectPUT.html . Content-MD5 is not a required field. Meaning if it is not set by the client, the server should not error out, as you have already seen with AWS S3. As far as minio-go sdk is concerned, content-MD5 cannot be set via PutObjectOptions as explained in https://docs.minio.io/docs/golang-client-api-reference#FPutObject

    Minio-go sets X-Amz-Content-Sha256 in the case of http connection and Content-Md5 in the case of https connections. Minio-go's FPutObject and PutObject api abstracts both multi-part put and single part put into these APIs. In the case of multi-part PUT, each part will set either X-Amz-Content-Sha256 or Content-Md5 depending on the type of connection. Since the call is abstracted, it is not possible for a user to set Content-Md5.

    I believe IBM Cloud Object Storage has a bug as it should not error out, even if Content-Md5 is not set.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧