Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentMD5 for s3.getSignedUrl #675

Closed
thattommyhall opened this issue Aug 4, 2015 · 5 comments
Closed

ContentMD5 for s3.getSignedUrl #675

thattommyhall opened this issue Aug 4, 2015 · 5 comments

Comments

@thattommyhall
Copy link

I can't get a signed request to work with ContentMD5.

If I do

var s3_params = {
  Bucket: bucketName,
  ContentType: 'image/jpeg',
  ContentMD5: "f0oxEyT+4qR3E/70ID0PfA==",
  ACL: 'public-read',
  Key: 'TESTDIRECT.jpeg',
  Body: fs.readFileSync('/home/thattommyhall/TEST.jpg')
};


s3.putObject(s3_params, function(err, data){
  if(err){
    debug('put', 'error', err);
  }
  else {
    // debug('put', data);
  }
});

It works, but

var s3_params_sign = {
  Bucket: bucketName,
  ContentType: 'image/jpeg',
  ContentMD5: "f0oxEyT+4qR3E/70ID0PfA==",
  ACL: 'public-read',
  Key: 'TESTsigned.jpeg',
  Expires: 6000,
};

s3.getSignedUrl('putObject', s3_params_sign, function(err, url){
  if(err){
    debug('error', err);
  }
  debug(url);
});

will not work if I have ContentMD5.

I have tried adding Content-MD5 headers to the put (as the content type was not set until I added headers).

I made a project at https://github.com/thattommyhall/aws-sdk-bug, you should be able to run

$ node example.js | python upload.py 

(but I have also tried it with curl --upload-file )

@AdityaManohar
Copy link
Contributor

@thattommyhall I see here that you are creating the signed url without the ContentMD5 parameter set.

You will have to create a signed url with the ContentMD5 parameter as well as set the Content-MD5 header when PUTting to the signed URL.

For example:

// NOTE: This is a private API and may change in the future
var md5 = AWS.util.crypto.md5('hello' ,'base64');

var params = {
  Bucket: 'bucket', 
  Key: 'key', 
  ContentMD5: md5, 
  ContentType: 'text/plain'
}
var url = s3.getSignedUrl('putObject', params);

// Using jQuery in the browser
$.ajax({
  url: url, 
  method: 'PUT', 
  data: 'hello', 
  contentType: 'text/plain', 
  headers: {
    'Content-MD5': md5
  },
  success: callback
});

The above code works fine when PUTting to a pre-signed URL with Content-MD5 specified.

Hopes this helps clarify things!

@thattommyhall
Copy link
Author

I was commenting and uncommenting those lines, sorry I committed the one with it commented out.

I have updated the project, with the example directly PUTing using the request module immediately after generating the signed url using your code.

https://github.com/thattommyhall/aws-sdk-bug/blob/master/example.js

Both Content-MD5 are commented out now, but I have tried all 4 options of using them, the only one that works is not setting it in both the sign and PUT

@AdityaManohar
Copy link
Contributor

@thattommyhall I missed the fact that you're using the SigV4. I was able to reproduce the issue and I've pushed up a fix which should land in master soon.

Thanks very much for reporting this!

@AdityaManohar
Copy link
Contributor

@thattommyhall Can you also explain what your use case is that is causing this issue?

@lock
Copy link

lock bot commented Sep 29, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@lock lock bot locked as resolved and limited conversation to collaborators Sep 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants