SignatureDoesNotMatch error occurs when uploading a file using the PresignedURL created with the following source code.
File uploads are done via Postman.
Please tell me how to troubleshoot.
def call(env)
Aws.config.update({
region: '*region*',
credentials: Aws::Credentials.new('*accessKeyId*', '*secretAccessKey*')
})
key = "test/image.jpg"
bucket_name = '*bucket_name*'
signer = Aws::S3::Presigner.new(signature_version: 'v4')
if key
body = signer.presigned_url(:put_object, bucket: bucket_name, key: key)
else
body = ""
end
body
end
I have checked if the accessKeyId, region, secretAccessKey and bucket_name are correct.
Response Header Example(some are masked):
HTTP/1.1 403 Forbidden
x-amz-request-id: *request-id*
x-amz-id-2: sSbb********************************************************************98=
Content-Type: application/xml
Transfer-Encoding: chunked
Date: Mon, 21 Nov 2022 01:49:12 GMT
Server: AmazonS3
Response Body Xml Example(some are masked):
<?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>*Here is accessKeyId*</AWSAccessKeyId><StringToSign>AWS4-HMAC-SHA256
20221121T014413Z
20221121/ap-northeast-1/s3/aws4_request
d1ffe599b69868e*********************************************25a3</StringToSign><SignatureProvided>4f51*********************************************db31f6******f735</SignatureProvided><StringToSignBytes>41 57 ...*Byte array follows here*</StringToSignBytes><CanonicalRequest>PUT
/test/Receipt3.jpg
X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=*Here is accessKeyId*%2F20221121%2Fap-northeast-1%2Fs3%2Faws4_request&X-Amz-Date=20221121T014413Z&X-Amz-Expires=900&X-Amz-SignedHeaders=content-type%3Bhost&x-amz-acl=public-read
content-type:image/jpeg
host:*bucket name*.s3.ap-northeast-1.amazonaws.com
content-type;host
UNSIGNED-PAYLOAD</CanonicalRequest><CanonicalRequestBytes>50 55 ...*Byte array follows here*</CanonicalRequestBytes><RequestId>*request-id*</RequestId><HostId>sSbbjrOYs9d4aAf************GSIvc************CSJhGPR************98=</HostId></Error>
Related
Below web API returns JSON for the given ID.
http://aws-av-devser/Assigning_ID/api/QidMasters/2
It's working as expected in postman.
but when I try to consume this web API in different projects on the same server. I am getting
404 Not found Error
Below is the code to consume the web API
var uri = "http://aws-av-devser/Assigning_ID/api/QidMasters/2";
var response = await httpClient.GetAsync(uri);
Error Message :
{
StatusCode: 404,
ReasonPhrase: 'Not Found',
Version: 1.1,
Content: System.Net.Http.HttpConnectionResponseContent,
Headers:
{
Server: Microsoft-HTTPAPI/2.0
Date: Fri, 17 Jun 2022 17:59:28 GMT
Connection: close
Content-Type: text/html; charset=us-ascii
Content-Length: 315
}
}
Please correct me if I am missing something
Here is my code:
Here is the response:
2020/09/14 12:19:51.425: INFO Results for adding ppsEmailAddress as recovery email: {data=[object Object], finalURL=https://www.googleapis.com/admin/directory/v1/users/ttestaccount#pps.net, headers={Alt-Svc=h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43", Content-Length=357, Content-Type=application/json; charset=UTF-8, Date=Mon, 14 Sep 2020 19:19:51 GMT, Server=ESF, Vary=[Origin, X-Origin, Referer], X-Content-Type-Options=nosniff, X-Frame-Options=SAMEORIGIN, X-XSS-Protection=0}, initialURL=https://www.googleapis.com/admin/directory/v1/users/ttestaccount#pps.net, statusCode=400.0, statusReason=Bad Request}
Full code:
Trying to follow the Google API reference here, though something wrong with my syntax:
https://developers.google.com/admin-sdk/directory/v1/reference/users#resource
I made a similar request using the Google OAuth Playground
This was the format of my request:
PATCH /admin/directory/v1/users/youremail#joshgoldeneagle.com HTTP/1.1
Host: www.googleapis.com
Content-length: 45
Content-type: application/json
Authorization: Bearer {REPLACE WITH ACCESS TOKEN}
{
recoveryEmail: "yourPatchEmail#joshgoldeneagle.com"
}
Ensure that callGoogleAPI() makes a request in this format.
References:
https://developers.google.com/admin-sdk/directory/v1/reference/users/patch
I'm trying to implement a download link for users to download a record in .txt file.
Firstly it was a simple <a> tag
download
I could download the file from server in .txt format. But I found that it does not bring Auth header. So I tried to use a http get method to fetch it.
service.js
getCdrFile(url) {
return this.http.get<any>(`${this.env.service}/service/api/downloadFile?` + url);
}
component.js
downloadFile(url) {
this.service.getCdrFile(url).subscribe(
data => {
console.log(data);
},
error => {
console.log(error);
}
);
}
I can successfully call the API with auth head, then I got nothing happened after I clicked the download button but the txt data displayed in the "response" tab in Chrome developer tool. Also, I got nothing from console.log(data); inside my http request.
Is there anyway I can download the file? thanks!
(and here is my response detail)
# GENERAL
Request URL: http://localhost:8080/service/api/downloadFile?fileType=daily&trsDate=20190918
Request Method: GET
Status Code: 200
Remote Address: 127.0.0.1:8080
Referrer Policy: no-referrer-when-downgrade
# RESPONSE HEADER
Accept-Ranges: bytes
Access-Control-Allow-Origin: *
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Connection: keep-alive
Content-Disposition: attachment; filename=20190918.txt
Content-Type: application/json
Date: Wed, 02 Oct 2019 03:51:01 GMT
Expires: 0
Pragma: no-cache
Server: nginx/1.15.2
Transfer-Encoding: chunked
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
X-XSS-Protection: 1; mode=block
You can create a Blob response and create a blob url with it and download on the fly.
Service:
Modify your service to receive a blob response
getImage() {
return this.httpClient.get(
your_image_link,
{
responseType: 'blob', // <-- add this
headers: {your_headers}
}
);
}
Component:
On click of your link on the page call your service to get the response blob of your file
Create a blob url URL.createObjectUrl method
Create a dummy anchor element assign the blob url and name of the file to download
Trigger a click event on the anchor element
remove the blob url from browser using URL.revokeObjectUrl method
downloadImage() {
this.service.getImage().subscribe(img => {
const url = URL.createObjectURL(img);
const a = document.createElement('a');
a.download = "filename.txt";
a.href = url;
a.click();
URL.revokeObjectURL(url);
});
}
Stackblitz: https://stackblitz.com/edit/angular-kp3saz
You have two ways to download the file from the server.
1:-) Ater getting a response from HTTP call to create base64 and create a dummy anchor tag and download.
2:-) Modify backend response as download response.
I am posting an https request to client's API ,testing from Postman API , I am getting proper response, response is in xml structure , however using the conventional way of httpsurlconnection api in java , I am getting response which is trimmed .
Response in Postman :
<data>
<status>02231013757|1518968|Failed</status>
<status>041580082657|1518969|Failed</status>
</data>
Response header in Java :
Server: Apache-Coyote/1.1Set-Cookie:JSESSIONID=68735C46DABA9D068FE1DB1D0FE83454; Path=/awp; Secure Expires: Thu, 01 Jan 1970 00:00:00 GMT Pragma: no-cache Content-Length: 14 Date: Wed, 19 Apr 2017 13:25:26 GMT Content-Type: text/html X-Powered-By: Servlet 2.5; JBoss-5.0/JBossWeb-2.1
Response fetched as String : <data></data>
As you can find the content-length is 14 in response header, so this issue is at client's service end or am I missing something ?
below snippet I am using to read the content :
read = new InputStreamReader(rc.getInputStream() );
StringBuilder sb = new StringBuilder();
int ch = read.read();
while( ch != -1 )
{
sb.append((char)ch);
ch = read.read();
}
resp = sb.toString();
I'm trying to connect to Parse.com 's REST-API via NSURLConnection to track AppOpened metadata.
I get 200 OK back from the API and the headers are the same to the cURL headers but my API calls are not being represented in the data browser on Parse.com . Is NSURLConnection doing something silly I don't know of? API response is the same but one request gets represented while the other one isn't.
NSLog output:
<NSHTTPURLResponse: 0x7ff5eb331ca0> { URL: https://api.parse.com/1/events/AppOpened } { status code: 200, headers {
"Access-Control-Allow-Methods" = "*";
"Access-Control-Allow-Origin" = "*";
Connection = "keep-alive";
"Content-Length" = 3;
"Content-Type" = "application/json; charset=utf-8";
Date = "Sun, 04 Jan 2015 22:42:54 GMT";
Server = "nginx/1.6.0";
"X-Parse-Platform" = G1;
"X-Runtime" = "0.019842";
} }
cURL output:
HTTP/1.1 200 OK
Access-Control-Allow-Methods: *
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=utf-8
Date: Sun, 04 Jan 2015 23:03:51 GMT
Server: nginx/1.6.0
X-Parse-Platform: G1
X-Runtime: 0.012325
Content-Length: 3
Connection: keep-alive
{}
It's the same output. What am I doing wrong? Has anyone experience with this?
Turns out Parse was showing funny API keys the moment I copied them out of the cURL example they provide in their lovely docs. Don't know whose analytics I screwed over but I'm terribly sorry and it wasn't my fault!
Always copy your API keys out of [Your-Parse-App-Name]->Settings->Keys
It probably was just a stupid glitch that happened on the Server.