question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sooooo ive got a problem

So, i am generating a signed S3 url on my server, and attempting to upload using this plugin. I can generate the url and upload a file using

How its worked before

curl -T file.jpg http://bla.s3.amazon.com/blahbahbla

How im doing it

When I attempt to upload the file from the browser like this

$upload.http({
    url:    decodeURIComponent(data.signed_url),
    method: 'PUT',
    data:   file,
    headers: {
        'Content-Type':file.type,
    }
}).progress(function(evt) {

    console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total));

}).success(function(data, status, headers, config) {

    console.log(data);

}).error(function(data, status, headers, config) {

    console.warn(data, status);

});

Response

I get a response like this

<?xml version="1.0" encoding="UTF-8"?>

<Error>SignatureDoesNotMatch<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message><StringToSignBytes>50 55 54 0a 0a 69 6d 61 67 65 2f 6a 70 65 67 0a 31 34 35 32 38 37 39 36 38 36 0a 78 2d 61 6d 7a 2d 61 63 6c 3a 70 75 62 6c 69 63 2d 72 65 61 64 0a 2f 62 67 70 72 6f 6f 66 2f 66 61 63 65 62 6f 6f 6b 3a 31 30 30 30 30 33 34 37 31 35 37 34 31 30 35 2f 33 65 31 62 36 64 32 39 2d 62 66 34 31 2d 34 37 62 31 2d 61 35 31 33 2d 30 38 38 61 39 63 30 32 61 39 62 63 2e 6a 70 67</StringToSignBytes><RequestId>CE628CB59F561A3D</RequestId><HostId>u5iLkvYLE0hRj30IU+qMS+XiwlwY/VXt8ZACxyot2KDwnLw5S2HL/pGgk4F/nHfr</HostId><SignatureProvided>hJg fYN2h6qz9jJATt4Zp A C94=</SignatureProvided><StringToSign>PUT

image/jpeg 1452879686 x-amz-acl:public-read /bgproof/facebook:100003471574105/3e1b6d29-bf41-47b1-a513-088a9c02a9bc.jpg</StringToSign><AWSAccessKeyId>MY_ACCESS_KEY</AWSAccessKeyId></Error>

Here are the headers for both requests

Req Headers

PUT /facebook:100003471574105/3e1b6d29-bf41-47b1-a513-088a9c02a9bc.jpg?AWSAccessKeyId=MY_ACCESS_KEY&Expires=1452879686&Signature=hJg+fYN2h6qz9jJATt4Zp+A+C94=&x-amz-acl=public-read HTTP/1.1 Host: bgproof.s3.amazonaws.com Connection: keep-alive Content-Length: 362867 Cache-Control: no-cache Pragma: no-cache Accept: application/json, text/plain, / Origin: http://localhost:5005 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36 Content-Type: image/jpeg Referer: http://localhost:5005/ Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8

Res Headers

HTTP/1.1 403 Forbidden Access-Control-Allow-Origin: * Access-Control-Allow-Methods: GET, PUT, DELETE Access-Control-Max-Age: 10000 Vary: Origin, Access-Control-Request-Headers, Access-Control-Request-Method x-amz-request-id: CE628CB59F561A3D x-amz-id-2: u5iLkvYLE0hRj30IU+qMS+XiwlwY/VXt8ZACxyot2KDwnLw5S2HL/pGgk4F/nHfr Content-Type: application/xml Transfer-Encoding: chunked Date: Wed, 15 Jan 2014 05:41:26 GMT Connection: close Server: AmazonS3

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:22 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
FoxUSAcommented, Apr 6, 2016

Again, this can be done. I have used this method on several enterprise projects

file.upload = Upload.http({
                    url: url,
                    data: file,
                    method: "PUT",
                    headers: {"Content-Type": file.type},
                }); 

where url is the pre-signed url. You must include the file.type in the url signing API call.

Example of the code you would put in your API.

var params = {
                Bucket:config.aws.bucket,
                Key:request.params[0].toLowerCase(),
                ContentType: request.query.contentType,
                ServerSideEncryption: "AES256"
            };
S3.getSignedUrl("putObject",params,s3PutCallback);
0reactions
bourgeois247commented, Mar 12, 2016

Spent a whole day on this, none of the suggestions worked for me. I needed a Php implementation for generating the policy and signature with version 4 of the AWS signature spec but NOT a signed url(so I still use <BUCKET_NAME>.s3.amazonaws.com for every upload), found this excellent article [https://www.designedbyaturtle.co.uk/2015/direct-upload-to-s3-using-aws-signature-v4-php/](Php S3 direct upload), changed the data section specified in the ng-file-upload docs to the fields specified in the article, and it works.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uploading objects - Amazon Simple Storage Service
You can upload any file type—images, backups, data, movies, etc.—into an S3 bucket. The maximum size of a file that you can upload...
Read more >
How To Upload File to S3 with the AWS CLI
Learn how to use the AWS CLI tool to upload, download, and synchronize files and folders between local locations and AWS S3 buckets....
Read more >
Uploading files — Boto3 Docs 1.26.37 documentation
The AWS SDK for Python provides a pair of methods to upload a file to an S3 bucket. The upload_file method accepts a...
Read more >
AWS S3 - Uppy
The @uppy/aws-s3 plugin can be used to upload files directly to an S3 bucket. Uploads can be signed using either Companion or a...
Read more >
aws-sdk.S3.upload JavaScript and Node.js code examples
console.log(`Uploading ${fileName}: ${events.length} events...`); await s3.upload(params).promise();
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found