I have this code
<%= form_for(:img, url: {action: "postodb"}) do |f| %>
<div id="image-preview">image here!</div>
<%= f.submit "Send to database" %>
<%end%>
Here <input type="image">
is added from a js file
var imageDiv = $("#image-preview");
imageDiv.html('<input type="image" name="img1" style="margin-left:146px"id="spiro-img" src="'+img+'"/>');
This all works fine..
Next I want to send this to the folder but it doesnt work
This is the code I have in the controller(referred from this site http://rohitrox.github.io/2013/07/19/canvas-images-and-rails/)
def postodb
data = params[:data_uri]
image_data = Base64.decode64(data['data:image/png;base64,'.length .. -1])
File.open("/public/uploads/somefilename.png", 'wb') do |f|
f.write image_data
end
end
This is the error I get
Plz help.
Using carrierwave gem for loading images.
First what your should to do is read a docs: http://www.w3schools.com/Tags/att_input_type.asp
Second what your should learn to read is logs. At screenshot you have section with params, and there is no
data_uri
key.And finaly use the
<input type='file' ... />
for upload. If you want beauty async upload with preview, you should look onjquery-file-upload
gem instead.P.S.:
type='image'
is a submit button with image.