Although it took me a while, I recently encountered an issue with uploading an image using the javascript version of the AWS SDK to create a presigned URL. In case anyone else is facing similar problems, here's how I managed to solve it.
The key to resolving the problem lies in understanding the StringToSign
element that triggers the SignatureDoesNotMatch
error from Amazon. In my scenario, the StringToSign
looked something like this:
<StringToSign>
PUT\n\nmultipart/form-data; boundary=+++++org.apache.cordova.formBoundary\n1481366396\n/bucketName/fileName.jpg
</StringToSign>
When generating a presigned URL for S3 upload using the aws-sdk
, a string is constructed based on various request elements and hashed using your AWS secret. The resulting signature is appended to the URL as a parameter. If the hashes don't match during the upload request, the SignatureDoesNotMatch
error occurs.
To prevent this error, you need to ensure that the string generated by the aws-sdk
matches the one created by the server. This can be achieved by modifying the code within the sign
method found in
node_modules/aws-sdk/lib/signers/s3.js
.
By adjusting the request headers and content types specified in both the presigned URL generation and the client-side file upload, you can sync the signing strings and successfully upload files to your bucket.