I'm trying to get the PaperClip params by using jQuery and create an image directly.
i did something like
imageData = new FormData();
imageData.append('image', $('input[type=file]')[0].files[0]);
and I passed the imageData
to a ruby function like
send_message: function(imageData) {
return this.perform('send_message', {
image: imageData
});
but when I tried to create a message like
Messages.create!(image: data['image'])
it returns an error
Could not execute command from ({"command"=>"message", "identifier"=>"{\"channel\":\"ConversationsChannel\", "data"=>"{\"image\":{},\"action\":\"send_message\"}"})
[Paperclip::AdapterRegistry::NoHandlerError - No handler found for {}]
No idea why imageData == {}
while $('input[type=file]')[0].files[0])
returns something like
File {name: "image.png", lastModified: 1499752728000, lastModifiedDate: Tue Jul 11 2017 13:58:48 GMT+0800 (HKT), webkitRelativePath: "", size: 602802…}
I know that PaperClip requires something like this in params
, but not sure how to get this from 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>>}