I am trying to upload a PDF file to AWS S3 using multi part uploads. However, when I send the PUT
request for uploading the part, I receive a SignatureDoesNotMatch error.
<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
My Server Code (Node) is as below:
CREATE MultiPart Upload
const AWS = require('aws-sdk');
AWS.config.region = 'us-east-1';
const s3 = new AWS.S3({ apiVersion: '2006-03-01' });
const s3Params = {
Bucket: 'bucket-name',
Key: 'upload-location/filename.pdf',
}
const createRequest = await s3.createMultipartUpload({
...s3Params
ContentType: 'application/pdf'
}).promise();
GET Signed URL
let getSignedUrlParams = {
Bucket: 'bucket-name',
Key: 'upload-location/filename.pdf',
PartNumber: 1,
UploadId: 'uploadId',
Expires: 10 * 60
}
const signedUrl = await s3.getSignedUrl('uploadPart',getSignedUrlParams);
And the Client code (in JS) is :
const response = await axios.put(signedUrl, chunkedFile, {headers: {'Content-Type':'application-pdf'}});
A few things to note:
- This code works when I allow all public access to the bucket.However, if all public access is blocked, the code does not work.
- With all public access blocked, I am still able to upload to the bucket with the same credentials using aws cli.
- I already have tried re-generating AWS Access Key ID and Secret Access Key and that didnt help.
Not able to figure out what the problem is. Any help would be appreciated.
PS: This is the first question I have posted here. So please forgive me if I havent posted it appropriately. Let me know if more details are required.