S3 Upload
See original GitHub issueSooooo 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:
- Created 10 years ago
- Comments:22 (7 by maintainers)
Again, this can be done. I have used this method on several enterprise projects
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.
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.