Cordova - Uploading to Google App Engine signedUrl - Content-MD5 not matching

Viewed 69

Having a bit of an issue; I am trying to upload to a PUT signed url - but any time I add in 'content-md5' to my upload header GCS responds with

<Message>The MD5 you specified in Content-MD5 or x-goog-hash was invalid.</Message>
<Details>Invalid MD5 value: ZWFmMjRlNmE0OTExMjRhMTllYmYxYzU2ODliOWIyZGE=</Details>

I can confirm that eaf24e6a491124a19ebf1c5689b9b2da is the correct MD5, and I am providing it in base64 form. When I upload the file manually to my bucket and check the MD5 content it matches with eaf24e6a491124a19ebf1c5689b9b2da.

My signed URL is being made with

$url = $object->signedUrl(
    new \DateTime("60 min"),
    [
        "method" => "PUT",
        'version' => 'v4',
        "contentType" => "application/octet-stream"
        "contentMd5" => base64_encode($md5)
    ]
);

On the Cordova side I am using the FileTransfer plugin

    var uploadFileTransfer = new FileTransfer();

    var options = new FileUploadOptions();
    options.fileKey = "file";
    options.httpMethod = "PUT";
    options.fileName = "my_file.zip";
    options.mimeType = "application/octet-stream";
    options.headers = {
        "content-md5": btoa(fileMd5),
        'content-type': 'application/octet-stream'
    }


    uploadFileTransfer.upload(file, url, success, fail, options);

If I remove content-md5, the upload works. Any help is greatly appreciated here, thanks.

0 Answers
Related