テキスト エディターを独自に実装しており、ユーザーがファイルをテキスト エディターにドラッグ アンド ドロップしてアップロードできるようにしたいと考えています。エディターは iframe を使用します。rails と remotipart を使用して、画像ファイルの非同期アップロードを行っています。このプラグインを使用してみました: http://chrismbarr.github.io/FileDrop/ しかし、remotipart を使用してファイルをアップロードする方法がわかりません。私はAJAXを使用してみましたが、それは正しい方法ではなく、さらに機能しないと確信しています:
$('#wysiwygtextfield').contents().find("html").fileDrop(
{
onFileRead:function(fileCollection){
$.each(fileCollection, function(){
// I should probably be uploading files to the server using remotipart here.
// the plugin iterates through the collection of files that are dropped
});
},
removeDataUriScheme: true
});
}) ;
さらにコード、アップロード アクション、または html が必要な場合はコメントしてください。次のフォームを使用して、remotipart gem を使用してファイルの非同期アップロードを行っていますが、正常に動作します。
<%= form_for(:image, :remote => true , :url => 'upload',:multipart => true ,
:html => { :id => 'upload_qimage'}) do |f| %>
<%= f.file_field :image, :placeholder => 'No file chosen',:onchange => "$(this).parents('form').submit(); before_submit() ; ",class: "image_textbox" %>
<% end %>