remotipart icon indicating copy to clipboard operation
remotipart copied to clipboard

Remotipart form send with post method

Open Badoche opened this issue 10 years ago • 12 comments

Hi,

I have some problems with remotipart, when I submit this form :

true, :html => { :multipart => true }) do |f| %>

When I click on my avatar (image_tag), the file field pop and once a file is selected, jquery submit the form.

But the form is sent with the POST method, not the PUT/PATCH (if I remove remote => true and submit the form manually, the method is the right one : PUT).

This is a remotipart issue ?

Using rails (4.0.0) Using jquery-ui-rails (4.1.1) Using remotipart (1.2.1)

Badoche avatar Mar 02 '14 18:03 Badoche

Try adding :method => :put to your form_for. So, your above snippet should look like this:

<%= form_for(@user, :remote => true, :html => { :multipart => true, :method => :put }) do |f| %>
  <%= f.file_field :avatar, style: 'display:none' %>
<% end %>

alexpls avatar Mar 20 '14 13:03 alexpls

Thanks for the reply, i've already tested this tip, but it didn't work : the form is sent with POST method.

I don't understand : when I don't use "remote => true" it's a PUT method, if I add it, it's a POST method :/

Badoche avatar Mar 22 '14 22:03 Badoche

the problem is here: https://github.com/JangoSteve/remotipart/blob/master/vendor/assets/javascripts/jquery.iframe-transport.js#L130 you need to copy method attribute from original form, but don't forget fallback to post

attenzione avatar Mar 31 '14 09:03 attenzione

Sorry but i don't understand what do you mean by copy method and fallback to post, can you explain me this more precisely please ?

Thank you for the reply, I understand where is the problem but I don't see clearly how to solve it :)

Badoche avatar Mar 31 '14 14:03 Badoche

@Badoche I think @attenzione proposed you to make some changes in source code to teach iframe transport to use custom method attribute base on original form data but by default use POST.

killthekitten avatar Aug 27 '14 13:08 killthekitten

this is better version of jquery.iframe-transport https://github.com/blueimp/jQuery-File-Upload/blob/master/js/jquery.iframe-transport.js

attenzione avatar Aug 27 '14 13:08 attenzione

@attenzione have you already got a working remotipart integration? I need the same unobtrusive behavior, but the original jquery.iframe-transport have different interface than that one from jQuery-File-Upload, so it can't be a drop-in replacement.

killthekitten avatar Aug 28 '14 09:08 killthekitten

i'm not, because don't need it, but solution should be easy, you need replace

form = $("<form enctype='multipart/form-data' method='post'></form>");

with something like this

options.type = (options.type || options.method).toLowerCase() || 'post';
form = $("<form enctype='multipart/form-data' method='" + options.type + "'></form>");

attenzione avatar Aug 28 '14 11:08 attenzione

@attenzione yes, I understand it. But I asked about using this version: https://github.com/blueimp/jQuery-File-Upload/blob/master/js/jquery.iframe-transport.js

killthekitten avatar Aug 28 '14 11:08 killthekitten

@killthekitten ou, can't help with it, sorry. In another project i'm just using bluimp file uploader, not remotipart

attenzione avatar Aug 28 '14 12:08 attenzione

@killthekitten, also you can check my update to this file, to be able to restore form file element on fail https://github.com/attenzione/remotipart/commit/73a4f7d752c17952ae4eb7b9cbc44d295ced2c38

attenzione avatar Aug 28 '14 12:08 attenzione

@attenzione seems that my problem was in something else, post/put/patch stuff works without any changes now. Re-checking.

killthekitten avatar Aug 28 '14 12:08 killthekitten