Ajax call with pre-signed URL giving error - Printable Version +- AWS Discussion Forum (https://letstalkaws.com) +-- Forum: Q & A (https://letstalkaws.com/forum-10.html) +--- Forum: Developer Help (https://letstalkaws.com/forum-24.html) +--- Thread: Ajax call with pre-signed URL giving error (/thread-25.html) |
Ajax call with pre-signed URL giving error - phanikumar - 09-09-2018 I have created a simple html page which contains an ajax call to API endpoint to retrieve pre-signed URL. Using the URL retrieved from the previous ajax call, I tried upload a sample text file which is resulting in the request signature we calculated does not match the signature you provided. Check your key and signing method response. But when I am using the same URL using CURL, it is working Good. Can someone suggest me what I am missing in the request. RE: Ajax call with pre-signed URL giving error - fzs - 09-09-2018 (09-09-2018, 01:02 AM)phanikumar Wrote: I have created a simple html page which contains an ajax call to API endpoint to retrieve pre-signed URL. Using the URL retrieved from the previous ajax call, I tried upload a sample text file which is resulting in the request signature we calculated does not match the signature you provided. Check your key and signing method response. But when I am using the same URL using CURL, it is working Good. Can someone suggest me what I am missing in the request. When you are sending the upload, are you also using Authorization Header method at the same time as the URL query method (pre-signed) to send the signature? You shouldn't if you are. My question is referring to this: https://docs.aws.amazon.com/general/latest/gr/sigv4-add-signature-to-request.html My other recommendation would be to use the SDKs to let the signature handling process be done automatically for you without worrying about security and signing issues. RE: Ajax call with pre-signed URL giving error - phanikumar - 09-09-2018 (09-09-2018, 11:17 AM)fzs Wrote:I am not using authorization headers. I am using the entire signed URL to make the Request. Also I do agree that using SDK is a good choice. But I have a situation where my code sits on Lambda function which has limitation of 6MB for file size and API Gateway has 10MB Payload limit. My files are too large and I can't handle that through Lambda and API Gateway. I am checking the possible ways to handle this. One other option that I am focusing on is multi-part upload. But I would like to get implement both to see the performance difference and advantages. I have attached the code for this forum which I am using to upload the code. Can you please have a look at the code and let me know if I am missing something(09-09-2018, 01:02 AM)phanikumar Wrote: I have created a simple html page which contains an ajax call to API endpoint to retrieve pre-signed URL. Using the URL retrieved from the previous ajax call, I tried upload a sample text file which is resulting in the request signature we calculated does not match the signature you provided. Check your key and signing method response. But when I am using the same URL using CURL, it is working Good. Can someone suggest me what I am missing in the request. RE: Ajax call with pre-signed URL giving error - fzs - 10-09-2018 (09-09-2018, 11:47 AM)phanikumar Wrote: I am not using authorization headers. I am using the entire signed URL to make the Request. Also I do agree that using SDK is a good choice. But I have a situation where my code sits on Lambda function which has limitation of 6MB for file size and API Gateway has 10MB Payload limit. My files are too large and I can't handle that through Lambda and API Gateway. I am checking the possible ways to handle this. One other option that I am focusing on is multi-part upload. But I would like to get implement both to see the performance difference and advantages. I have attached the code for this forum which I am using to upload the code. Can you please have a look at the code and let me know if I am missing something Please post the output of console.log(this.httpResponse) console.log(this.request.httpRequest) Quote:example RE: Ajax call with pre-signed URL giving error - phanikumar - 11-09-2018 When I added console log, I am getting the following response {readyState: 4, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …} abort: ƒ (e)always: ƒ ()catch: ƒ (e)done: ƒ ()fail: ƒ ()getAllResponseHeaders: ƒ ()getResponseHeader: ƒ (e)overrideMimeType: ƒ (e)pipe: ƒ ()progress: ƒ ()promise: ƒ (e)readyState: 4responseText: " <?xml version="1.0" encoding="UTF-8"?>↵<Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message> <AWSAccessKeyId>key</AWSAccessKeyId><StringToSign>PUT↵↵text/plain;charset=UTF-8↵1536703973↵x-amz-security-token: security Token</StringToSign><SignatureProvided>Signature</SignatureProvided> <StringToSignBytes>numbers </StringToSignBytes><RequestId>B2DE0E46BC5C7C96</RequestId><HostId>2VvhyRadrfdsGte/dsfsfdsde3XCedafa=</HostId></Error>"setRequestHeader: ƒ (e,t)state: ƒ ()status: 403statusCode: ƒ (e)statusText: "Forbidden"then: ƒ (t,r,i)__proto__: Object The above is the response that I got from JQuery request in the console RE: Ajax call with pre-signed URL giving error - phanikumar - 12-09-2018 Finally able to resolve the issue by adding content-type in aws s3 params. Thanks FZS for all the support |