From 0ea3a57ecb7c08d42b3e29521844f9f1a23cb84a Mon Sep 17 00:00:00 2001 From: "Dr.Rx" Date: Thu, 28 Feb 2019 16:31:07 -0500 Subject: [PATCH] azureblob: Enable MD5 checksums when uploading files bigger than the "Cutoff" This enables MD5 checksum calculation and publication when uploading file above the "Cutoff" limit. It was explictely ignored in case of multi-block (a.k.a. multipart) uploads to Azure Blob Storage. --- backend/azureblob/azureblob.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/backend/azureblob/azureblob.go b/backend/azureblob/azureblob.go index 51aad65c4..7b7110b7f 100644 --- a/backend/azureblob/azureblob.go +++ b/backend/azureblob/azureblob.go @@ -1386,16 +1386,16 @@ func (o *Object) Update(in io.Reader, src fs.ObjectInfo, options ...fs.OpenOptio blob := o.getBlobReference() httpHeaders := azblob.BlobHTTPHeaders{} httpHeaders.ContentType = fs.MimeType(o) - // Multipart upload doesn't support MD5 checksums at put block calls, hence calculate - // MD5 only for PutBlob requests - if size < int64(o.fs.opt.UploadCutoff) { - if sourceMD5, _ := src.Hash(hash.MD5); sourceMD5 != "" { - sourceMD5bytes, err := hex.DecodeString(sourceMD5) - if err == nil { - httpHeaders.ContentMD5 = sourceMD5bytes - } else { - fs.Debugf(o, "Failed to decode %q as MD5: %v", sourceMD5, err) - } + // Compute the Content-MD5 of the file, for multiparts uploads it + // will be set in PutBlockList API call using the 'x-ms-blob-content-md5' header + // Note: If multipart, a MD5 checksum will also be computed for each uploaded block + // in order to validate its integrity during transport + if sourceMD5, _ := src.Hash(hash.MD5); sourceMD5 != "" { + sourceMD5bytes, err := hex.DecodeString(sourceMD5) + if err == nil { + httpHeaders.ContentMD5 = sourceMD5bytes + } else { + fs.Debugf(o, "Failed to decode %q as MD5: %v", sourceMD5, err) } }