s3_direct_upload icon indicating copy to clipboard operation
s3_direct_upload copied to clipboard

Help With Working Example?

Open nicholasmartin opened this issue 11 years ago • 19 comments

Hey all, I've been struggling for days with Carrierwave and Carrierwave_direct and I just can't get it to upload to a specific S3 directory (each member of my application needs to be able to upload to their own directory).

Anyway, I've been looking at S3 Direct Upload but am a little hesitant to try it out, mainly because the documentation about persisting the data is not 100% clear to me (still earning rails and very new to javascript).

I was wondering if any kind soul out there could share a super simple example of how you use S3 Direct Upload to upload and save S3 file information on a model.

I do apologize if this is too noobish...

nicholasmartin avatar Jul 04 '13 14:07 nicholasmartin

Found this blog post on using S3 Direct Upload with Paperclip (we're currently using Paperclip, otherwise we'd probably go with Carrierwave also). Either way, it might help.

nathany avatar Jul 05 '13 20:07 nathany

That's my blog post. Let us know if you have any questions. :)

uberllama avatar Aug 12 '13 22:08 uberllama

@uberllama @nathany If you'd be kind enough, could you please put up a simple s3_direct_upload application as an example? I'm very new to Rails & Javascript and can't get it to work despite working on it for days. Most of us noobs would really appreciate your help. Thanks!

sheharyarn avatar Dec 02 '13 20:12 sheharyarn

@PsychoSherry Sorry, I don't have an application like that to share. I did write a little bit on the process we used. Not sure if that helps though.

nathany avatar Dec 03 '13 01:12 nathany

@nathany I got it to work. It seems that I've been having the same problem as this guy. Using the monkeypatch in the comments, it started working. Thanks anyways.

sheharyarn avatar Dec 03 '13 13:12 sheharyarn

@lifestylenetworker I don't know if you were able to complete your app, but this gem does need a simple working example. So I took the time out to make one. Just putting this here if any one needs it.

S3 Direct Upload Example

sheharyarn avatar Dec 03 '13 17:12 sheharyarn

Hey guys, I've been planning to make an example repo based off my blog post and still do. Out sick this week but will try and put one together soonoish.

uberllama avatar Dec 03 '13 18:12 uberllama

Has anyone gotten this to work with PUT the upload to an existing model record from the show page?

trbartel avatar Mar 26 '14 12:03 trbartel

Mmm, it does not work. I get this error

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

I've got CORS set as suggested but no luck.

JohnSmall avatar May 05 '14 13:05 JohnSmall

Are you using callback_method: "PUT" in your form helper? The upload to S3 will always be a POST, but you need to amend your callback method to tell your Rails controller that you're updating a file, not creating one.

uberllama avatar May 05 '14 13:05 uberllama

Ah, I was navigating to localhost:3000, but had 0.0.0.0:3000 set in my CORS configuration on the bucket. If I navigate to 0.0.0.0:3000, then I do see the progress bar going up, but then I get an error

POST https://{my-bucket-name}.s3-eu-west-1.amazonaws.com/ 400 (Bad Request)

And nothing is saved in the bucket.

JohnSmall avatar May 05 '14 14:05 JohnSmall

I just changed my CORS configuration to allow access from http://localhost:3000, and I get the same problem.

JohnSmall avatar May 05 '14 14:05 JohnSmall

Try using * for your allowed origin on your dev bucket and see if it works.

uberllama avatar May 05 '14 14:05 uberllama

OK I did that and it makes no difference. I'm still getting POST https://{my-bucket-name}.s3-eu-west-1.amazonaws.com/ 400 (Bad Request)

Though the progress bar does go up.

JohnSmall avatar May 05 '14 14:05 JohnSmall

I went back to https://github.com/pjambet/direct-upload which is supposedly the basis of the s3_direct_upload gem. After fiddling about with different names for the exported AWS params, I got it working. Horray!

So it must be doing something that the s3_direct_upload isn't doing. But what could it be?

JohnSmall avatar May 05 '14 15:05 JohnSmall

@JohnSmall could you be more specific about your fiddling? I'm running into the same issue on a new site, which is kind of odd because I've used this approach dozens of times successfully.

chrishawk avatar Feb 21 '15 12:02 chrishawk

@JohnSmall @chrishawk I'm facing the same issue too, have you managed to fix it?

kelset avatar Feb 26 '16 15:02 kelset

same problem here. bar loads up, but s3 gives an error 400. any improvements on this? or some one who has same problem, u guys solved it?

fatihtas avatar Feb 17 '17 12:02 fatihtas

@fatihtas - I found changing my bucket from London to Ireland sorted it out.. The issue I has was around authorisation.. https://stackoverflow.com/questions/26533245/the-authorization-mechanism-you-have-provided-is-not-supported-please-use-aws4

AndrewCowle avatar Jan 10 '18 22:01 AndrewCowle