tors / jquery-fileupload-rails

jQuery File Upload integrated for Rails
669 stars 254 forks source link

Rails update to 3.2.13 breaks multiple upload #36

Closed hallmatt closed 9 years ago

hallmatt commented 11 years ago

I'm using the multiple option to choose an upload multiple photos, which works fine in Rails 3.2.12, but once I upgrade to 3.2.13 the functionality fails. However, if I remove the multiple: true option in the form helper, it also uploads images fine...but this multiple option is a necessity (unfortunately).

I'm using Paperclip to handle the files and receive an error in the logs stating: Paperclip::AdapterRegistry::NoHandlerError - No handler found for [#<ActionDispatch::Http::UploadedFile:0x007fdb5d070888 @original_filename="C70476_File002_Large.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"machine_image[image][]\"; filename=\"C70476_File002_Large.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/var/folders/2c/2hqcq4k55g1_v_h447vn96q40000gn/T/RackMultipart20130319-14961-7i2zm1>>]

Any thoughts on this? I'm not sure if this is a Paperclip or a jQuery Fileupload-Rails issue . Here's my form:

= simple_form_for [@machine, MachineImage.new], :html => {:multipart => true} do |f|
  =f.input :image, label: "Upload image(s):", :input_html => { multiple: true, name: "machine_image[image]" }

Here's my Javascript/Coffeescript:


jQuery ->
  $("#new_machine_image").fileupload
    dataType: "script"
    add: (e, data) ->
      types = /(\.|\/)(gif|jpe?g|png)$/i
      file = data.files[0]
      if types.test(file.type) || types.test(file.name)
        data.context = $(tmpl("template-upload", file))
        $('#new_machine_image').append(data.context)
        data.submit()
      else
        $("#upload-errors ul").prepend("<li>#{file.name} is not a gif, jpeg, or png image file.</li>")
        $("#upload-errors").show()
        # alert()
    progress: (e, data) ->
      if data.context
        progress = parseInt(data.loaded / data.total * 100, 10)
        data.context.find('.bar').css('width', progress + '%')
    done: (e, data) ->
      if data.context
        data.context.hide()

Any help or direction on this would be greatly appreciated. Thanks!

cthiel commented 11 years ago

I suspect this is fallout from https://github.com/rails/rails/commit/488699166c3558963fa82d4689a35f8c3fd93f47

See

-          options["name"] += "[]" if options["multiple"]
+          options["name"] += "[]" if options["multiple"] && !options["name"].ends_with?("[]")
cthiel commented 11 years ago

Turns out, downgrading rails to 3.2.12 doesn't solve this. Going to 0.4.0 for jquery-fileupload-rails + rails 3.2.12 makes this function OK again. (3.2.13 + 0.4.0 doesn't work either.)

SergeyKishenin commented 11 years ago

As a quick monkey-patch file_field_tag helper can be used with Rails 3.2.13 and jquery-fileupload-rails 0.4.1. It can accept custom name attribute without adding [] to it like:

<%= file_field_tag(:image, multiple: true, name: "machine_image[image]") %>

gomayonqui commented 11 years ago

Same happens to me, using rails 3.2.13 and jquery-fileupload-rails 0.4.17 when using multiple uploads it breaks. when I try to upload without multiple selection it works ok

alexandrule commented 11 years ago

Same for me, not working with multiple true, Rails 3.2.13.

mhenrixon commented 11 years ago

:+1:

euomarcelo commented 11 years ago

Adding this to my js works for me:

$('#fileupload').fileupload({ paramName: 'yourModel[fieldName]' });

Just remember to change the name accordingly (for me it was ''profile[avatar]'. This way you avoid adding the []s to the param's name

alexandrule commented 11 years ago

@euomarcelo :+1:

darrenterhune commented 11 years ago

@euomarcelo thanks, also worked for me

devsigner commented 11 years ago

@euomarcelo thanks. It worked !!!

Michael1969 commented 11 years ago

thanks worked for me to example: $('#fileupload').fileupload({ paramName: 'website_page[websiteimages_attributes][0][websiteimage]' });

digitalfrost commented 10 years ago

@tors This ticket can be closed.