jQuery-File-Upload icon indicating copy to clipboard operation
jQuery-File-Upload copied to clipboard

Upload multiple files directly to S3?

Open gangsteryepyedye opened this issue 14 years ago • 50 comments

I have been using Jquery-file-upload plugin with paperclip and S3 for quite a while now and I really like it. However, as the files I need to upload become bigger, uploading directly to S3 becomes my only choice.

This article demonstrates how to upload a single file to S3, unfortunately it doesn't do multiple files uploading.
https://github.com/blueimp/jQuery-File-Upload/wiki/Upload-directly-to-S3

so my question is, is it possible to iterate through a list of files and create a single post form for each file on the fly?

Or is it possible to create an independent form and then repopulate the field in each iteration?

Any tips are greatly appreciated.

gangsteryepyedye avatar Dec 30 '11 03:12 gangsteryepyedye

You would handle this in your processing script, which JFU hands off to. I have implemented this approach in two PHP based projects I am working on, and it isn't too difficult.

What language are you working with?

chrisjdavis avatar Jan 09 '12 16:01 chrisjdavis

I'm going to be doing this same thing - uploading multiple files directly to S3. I will be using node.js/express. Anyone with experience with that?

eltoro avatar Jan 16 '12 16:01 eltoro

I'm in the exact same boat.

The best I've been able to figure out is to loop through the .files of the $fileinput and then pass those into the "add" API of the plugin. I can't seem to get the form post to S3 quite right though. I assign data.form to the actual form, since the plugin can't figure it out from what gets passed into add (just a file object). That ends up not including a file input (since it's just working with a file object instead of the entire file input), which I think is part of the problem. It looks like the plugin _should be able to take just a file object and post it somehow, but that doesn't seem to work. Furthermore, I end up with this response from S3 that doesn't make a ton of sense "InvalidArgumentConflicting query string parameters: acl, policyaclResourceType"

Anyway, I'm not surprised it isn't working, since I've really had to hack my way just to get this far. I started working with the same guide, and before I tried to enable multiple file support, it worked great. Any hints on the right direction to head would be greatly appreciated.

gorman avatar Jan 17 '12 06:01 gorman

I was using JFU with Ruby before I switched to a flash plugin. The flash one works well except it does not support drag and drop feature, but I am willing to trade it with the speed that flash plugin provides.

238357 avatar Jan 17 '12 07:01 238357

Thanks for the quick response and suggestion. I really was hoping to stick with a non-flash solution, but I may look into it.

On Jan 16, 2012, at 11:57 PM, [email protected] wrote:

I was using JFU with Ruby before I switched to a flash plugin. The flash one works well except it does not support drag and drop feature, but I am willing to trade it with the speed that flash plugin provides.


Reply to this email directly or view it on GitHub: https://github.com/blueimp/jQuery-File-Upload/issues/910#issuecomment-3524480

gorman avatar Jan 17 '12 08:01 gorman

I'm just starting it but I'll let you know how it goes. I'm using express so I'll grab the uploads with req.files and then I'm using Knox to read the files into memory and then do a PUT.

eltoro avatar Jan 18 '12 17:01 eltoro

Why not a full browser-side solution?

I implemented JFU to upload files directly to S3 with no need to contact the server apart from the inicial generation of the page. Just need it to upload each file separately instead of Posting all files once which is not supported by S3.

Any way to force iframe based posting to make a single post for each file like the default behavior? Or do we need to hack a bit to get there?

JonnyBGod avatar Feb 05 '12 18:02 JonnyBGod

I need to collect some info on the upload and store it in mongo. So now I'm looping through req.files.uploads and then uploading to S# with Knox, inserting into mongo, building the return json and then sending the response. It all works fine but I'm having to write the files because I'm not sure how to grab the writeStream directly.

eltoro avatar Feb 05 '12 20:02 eltoro

I'm able to upload straight to S3 with multiple files in parallel and file progress using this plugin. The trick is to create the upload form on the fly and store it on S3 as well to get around the same origin policy. I will post some code soon.

ncri avatar Feb 18 '12 13:02 ncri

Another option is to just have a static file on S3 and pass the necessary fields to the static file using something like http://benalman.com/projects/jquery-postmessage-plugin/ -- that way you're not having to keep regenerating the file and you can pass other information to and from the iframe (upload progress, guid, etc). With this iframe approach, I've managed to get direct S3 uploading with multiple files, dropzones and upload progress working all without the user realizing there's an iframe/external page involved.

gorman avatar Feb 18 '12 19:02 gorman

Sounds cool! With my solution though it works transparently too, the user doesn't notice being on an external page/iframe... But using postMessage sounds more elegant...

ncri avatar Feb 18 '12 21:02 ncri

Hm, from your link, do I understand it right that you can only communicate from the frame to its parent, not the other way round? To embed an upload form in an iFrame with dynamic params you need to communicate from parent to frame. Are you simply passing query url parameters? If so, postMessage is not even necessary...

ncri avatar Feb 18 '12 22:02 ncri

Actually it works fine simply passing the dynamic parameters to the iframe and then reading them from within the form on s3. I just tested it. So no need for postMessage.

ncri avatar Feb 19 '12 00:02 ncri

Yeah, that's true -- all of the necessary parameters can be passed directly when calling the iframe. postMessage is useful for sending triggers back to the parent though -- when the file is uploading, what the progress is and when it's done.

gorman avatar Feb 19 '12 18:02 gorman

Well, you can also display the progress in the iframe, that's what I do.

ncri avatar Feb 19 '12 21:02 ncri

Could you guys share us a working example for this?

samnang avatar Feb 20 '12 07:02 samnang

Hi @samnang, I will post an example rails application as soon as it's ready. It's working, but I have some issue with after upload callbacks. Crossdomain Ajax is not supported in some browsers (like Opera), so I will use postMessage as @gorman suggested, as it has wider browser support. Should have something ready later this week.

ncri avatar Feb 20 '12 07:02 ncri

I should mention that I actually decided to switch to Plupload because I had better luck getting it to work cross-browser (unfortunately, I can't remember exactly why), although I do like jQuery File Upload better (I don't use any of it's Flash stuff though). I'm curious to see @ncri's sample in action, as I'd love to switch back.

gorman avatar Feb 20 '12 07:02 gorman

Okay, stay tuned... ;-)

ncri avatar Feb 20 '12 07:02 ncri

Okay, I got an example app up: https://github.com/ncri/s3_uploader_example Please let me know what you think, or if you have troubles getting it working.

ncri avatar Feb 22 '12 11:02 ncri