我正在尝试使用jQuery获取PaperClip参数并直接创建图像。
我做了类似
的事情imageData = new FormData();
imageData.append('image', $('input[type=file]')[0].files[0]);
我将imageData
传递给像
send_message: function(imageData) {
return this.perform('send_message', {
image: imageData
});
但是当我尝试创建像
这样的消息时Messages.create!(image: data['image'])
它会返回错误
Could not execute command from ({"command"=>"message", "identifier"=>"{\"channel\":\"ConversationsChannel\", "data"=>"{\"image\":{},\"action\":\"send_message\"}"})
[Paperclip::AdapterRegistry::NoHandlerError - No handler found for {}]
当imageData == {}
返回类似
$('input[type=file]')[0].files[0])
File {name: "image.png", lastModified: 1499752728000, lastModifiedDate: Tue Jul 11 2017 13:58:48 GMT+0800 (HKT), webkitRelativePath: "", size: 602802…}
我知道PaperClip在params
中需要这样的东西,但不知道如何从jQuery中获取此内容
"asset"=>
{"image"=>
#<ActionDispatch::Http::UploadedFile:0x000000056679e8
@content_type="image/jpg",
@headers= "Content-Disposition: form-data; name=\"asset[image]\";
filename=\"2009-11-29-133527.jpg\"\r\nContent-Type: image/jpg\r\n",
@original_filename=""2009-11-29-133527.jpg"",
@tempfile=#<File:/tmp/RackMultipart20120619-1043-yvc9ox>>}