HTML5 FormData file upload with RubyOnRails

人走茶凉 提交于 2019-12-04 04:13:38
Ian Selby

Have you seen this issue? Sending multipart/formdata with jQuery.ajax

It looks like you might be running into jQuery adding content-type headers, which causes the boundary string to be missing. From the above linked issue:

It’s imperative that you set the contentType option to false, forcing jQuery not to add a Content-Type header for you, otherwise, the boundary string will be missing from it. Also, you must leave the processData flag set to false, otherwise, jQuery will try to convert your FormData into a string, which will fail.

Based on that, give this a try:

$.ajax({
  url: $('.uploader').attr('action'),
  contentType: false,
  cache: false,
  processData: false,
  type: 'POST',
  dataType: 'json',
  data: data
});

I haven't tried this myself, but I suspect this might be the droids you're looking for :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!