nathancolgate / s3-swf-upload-plugin

A rails 3 gem which allow user upload files to S3 through an embedded flash directly. All UI has been moved out of flex and can be controlled by CSS and JavaScript callbacks.
http://www.nathancolgate.com
MIT License
317 stars 74 forks source link

Feature request: Change filename & keyPrefix through JavaScript after init #17

Closed mattheworiordan closed 10 years ago

mattheworiordan commented 14 years ago

Hi Nathan

Love this plugin btw, you have really saved the day for me today...

One thing that would be really nice however would be to allow a filename & keyPrefix to be explicitly set for the SwfUpload object after it's been initialized. The reason I need this is as follows:

Not sure how difficult this would be, but I think it would add a lot.

Thanks, Matthew

AdnanTheExcellent commented 13 years ago

This feature request is the exact same request i was going to ask for. I have a problem with setting up s3 where i cannot rename the files that customers are uploading form my site. My database renames files in a certain way to prevent same-name files and also to organize the database, and i need users to upload the files directly to s3 and have the same namign scheme as what the database would use.

mischa78 commented 13 years ago

Me too. It would be great if this is possible.

andrewhavens commented 12 years ago

I would also really like to have this ability. The current state of this plugin is that you have to specify all that information when the SWF is initialized. The side effect of this is that you can only have one uploader initialized per page. I ran into a situation where I had a list view and needed to initialize a separate uploader for each item, but this plugin was not flexible enough to handle that situation so I had to come up with a different solution. It would be great if you didn't have to specify any details except maybe the button image when it is initialized, then before the uploading starts, you could fill in the blanks specific to the file(s) that are about to be uploaded. I found some other Amazon S3 uploaders that work like this (and are Sinatra compatible) but I ended up not being able to use them. If this library could support this feature, it would be much appreciated. =]

AdnanTheExcellent commented 12 years ago

I have added the functionality to change the filename and keyprefix a while ago, but I have changed the uploader so much and customized it specific to my website that it probably would not help much if i posted my code. Here is what you need to do:

  1. In s3queue.as, at the beginning of uploadNextFile() you must add either an HTTP Post to your rails server to get the ID, or an ExternalInterface call so you can do an ajax post. For the externalinterface you may need to add a few things in the js/rails to get the externalinterface call to work. You can use any of the external calls in the uploader as an example to get it working.
  2. Update s3signature.as input parameters to take in the unique ID or some sort of hash for the filename/prefixpath that you received from the POST or externalinterface call. Then, in s3signature, change whatever you want in the initialization:

uploadoptions.FileName = UniqueID + "" + upload_options.OriginalName;

or

upload_options.key = prefixPath + UniqueID + '/' + upload_options.FileName;

hope this helps.

nathancolgate commented 10 years ago

Thanks, @AdnanTheExcellent for the solution!