使用 jQuery File Upload + Carrierwave + Rails 4 启用异步文件上传

Enabling Async file uploads with jQuery File Upload + Carrierwave + Rails 4

本文关键字:异步 启用 文件 Rails jQuery File Upload Carrierwave 使用      更新时间:2023-09-26

我试图允许用户在文件上传时在门户中移动。

这是我的表单代码:

<%= form_for [@myfolder, Myfile.new], html: { multipart: true, :id => "fileupload" }, :remote => true, do |f| %>
<%= f.file_field :attachment, multiple: true, style: "display:none;" %>
<% end %>

它命中创建操作 (POST),该操作使用 JSON 输出进行响应。

format.html { redirect_to @parentfolder, notice: 'Your file was successfully created.' }
format.js
format.json{ render :show, status: :created, location: @myfile }

这是我的应用程序中的 jquery 文件上传调用.js:

add: function(e, data) {
     data.context = $(tmpl("template-upload",data.files[0]))
     $('#fileupload').append(data.context)
     $('#inline-upload-status').show();
     $.getJSON('/myfiles.json', function (result) {
        data.formData = result; // e.g. {id: 123}
        data.submit();
     });
  }

我无法弄清楚这段代码出了什么问题。文件上传未发生。

你为什么不试试像这个宝石远程处理这样的东西。