Open dima-shulga opened 7 years ago
I actually have the same issue, but I am doing request from PHP. Can someone please verify, that Ruby version in Readme and the latest version of this bundle, actually can upload to S3?
Let me look into this and reproduce this so I can debug.
I ran into this same issue. The problem is the S3 example in the README says to use the file.upload
method, but that method adds the multipart/form-data
content type header which as mentioned here is not compatible with binary uploads to S3: https://github.com/aws/aws-sdk-js/issues/547#issuecomment-86873980
I saw this solution (https://github.com/tim-evans/ember-file-upload/pull/12#issuecomment-315375492) which mentions there is an alternative method called uploadBinary
. As mentioned in the thread, the example in the README needs to be updated to the following for S3 uploads to work:
import Ember from 'ember';
const RSVP = Ember.RSVP;
const set = Ember.set;
export default Ember.Route.extend({
actions: {
uploadImage: function (file) {
let model = this.modelFor(this.routeName);
RSVP.cast(Ember.$.get('/api/s3_direct')).then(function (response) {
return file.uploadBinary(response.url, {
method: 'PUT',
contentType: file.blob.type,
data: JSON.stringify(response.credentials),
});
}).then(function (response) {
set(model, 'url', response.headers.Location);
return model.save();
});
}
}
});
Try adding Content-Type
to S3Params
when getting signed URL.
Current documentation still uses file.upload()
and not file.uploadBinary()
: https://adopted-ember-addons.github.io/ember-file-upload/docs/aws
@schleifer-john do you have time to provide a pull request fixing that one?
Try adding
Content-Type
toS3Params
when getting signed URL.
@Parrryy Is this something what should be added to our documentation? If so, please feel free to provide a pull request.
I needed to use uploadBinary or else the formData seems to be concatenated to the beginning of the file. What is the use case for using upload
instead of uploadBinary
?
What is the use case for using
upload
instead ofuploadBinary
?
uploadBinary
enforces a Content-Type: 'application/octet-stream'
which upload
does not: https://github.com/adopted-ember-addons/ember-file-upload/blob/c2d9ae84f4846f2dc924f1436e9df66e0838fa04/addon/file.js#L277-L282
When I specify a contentType for uploadBinary
I get an error:
file.js:43 Uncaught (in promise) TypeError: Cannot create property 'Content-Type' on string '{"key":"asdf.jpg"}'
It seems to pass through uploadBinary, then call the regular upload method.
Did something about the API change? I am stringifying the data
according to @schleifer-john 's approach.
I've done everything like in your tutorial except your Ruby script. I've used node js aws-sdk:
So I've got signed URL
Request URL:https://f.workdoer.com.s3.amazonaws.com/IMG_4875.PNG.png?AWSAccessKeyId=AKIAIFVWPIVVIGIONPXA&Expires=1502381111&Signature=Af9meXlMA7qj5HYALs7LzhWaftc%3D&x-amz-acl=public-read
And I've got from Amazon:
Something wrong with your request, because when I put it with CURL:
curl -k -X PUT -T "IMG_4875.PNG.png" "https://f.workdoer.com.s3.amazonaws.com/IMG_4875.PNG.png?AWSAccessKeyId=AKIAIFVWPIVVIGIONPXA&Expires=1502381111&Signature=Af9meXlMA7qj5HYALs7LzhWaftc%3D&x-amz-acl=public-read"
It's successfully uploaded. What I'm doing wrong?
Here is my bucket policy:
And cors:
Thanks for any help.