Monday, 28 May 2018

S3 Presigned URL Issue - file upload successful, 200 statusCode but no response body

This was working up until recently, I am not sure what has changed. I am generating a presignedUrl using S3 SDK and uploading a file to a bucket using it. The file actually uploads and the response returns a statusCode of 200 but weirdly there no response body.

I cannot understand if I'm missing some sort of header, or if they're wrong. The Content-length on the response headers worries me.

Any help would be much appreciated!

Note: I've obscured the values, if they are helpful I can mock them back in

General

Request URL: https://some-bucket.s3.ap-southeast-2.amazonaws.com/some/path/file/picture?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIAXXXap-southeast-2%2Fs3%2Faws4_request&X-Amz-Date=xxx&X-Amz-Expires=300&X-Amz-Security-Token=xxx&X-Amz-Signature=xxx&X-Amz-SignedHeaders=host%3Bx-amz-acl&x-amz-acl=public-read Request Method: PUT Status Code: 200 OK Remote Address: 1.2.3.4:443 Referrer Policy: no-referrer-when-downgrade

Request headers

Accept: application/json, text/plain, */* Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9 Cache-Control: no-cache Connection: keep-alive Content-Length: 31897 Content-Type: image/jpeg Host: some-bucket.s3.ap-southeast-2.amazonaws.com Origin: http://localhost:5000 Pragma: no-cache Referer: http://localhost:5000/some/page User-Agent: Mozilla/5.0 xxx

Response headers

Access-Control-Allow-Methods: GET, PUT, POST, HEAD Access-Control-Allow-Origin: * Content-Length: 0 Date: Thu, 1 May 2017 01:00:00 GMT ETag: "xxx" Server: AmazonS3 Vary: Origin, Access-Control-Request-Headers, Access-Control-Request-Method x-amz-id-2: xxx x-amz-request-id: xxx

Query String Parameters

X-Amz-Algorithm: AWS4-HMAC-SHA256 X-Amz-Credential: ASIAXXXap-southeast-2/s3/aws4_request X-Amz-Date: XXX X-Amz-Expires: 300 X-Amz-Security-Token: XXX X-Amz-Signature: XXX X-Amz-SignedHeaders: host;x-amz-acl x-amz-acl: public-read

Presigning service (NodeJS, Lambda)

... 
const params = {
    Bucket: 'some-bucket',
    Key: 'some/path/file/picture',
    Expires: 60 * 5,
    ACL: 'public-read'
};

s3.getSignedUrl('putObject', params, (err, url) => {
    ...
    callback(null, new Response(200, {url});
});
...

S3 service (TS, Angular)

public putObject(presignedUrl: string, file: File): Observable<any> {
  return this.http.put<any>(presignedUrl, file);
}

Component

this.s3Service.putObject(presignedUrl, file)
  .subscribe(
    (response) => {
      // it gets here as expected
      // but response is null!
    },
    () => {}
  );



from S3 Presigned URL Issue - file upload successful, 200 statusCode but no response body

No comments:

Post a Comment