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
}
@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.