发送< input type ="图片">到服务器上的文件夹 [英] Sending <input type="image"> to a folder on the server
问题描述
我有这个代码
<%= form_for(:img,url:{action:postodb}) do | f | %GT;
< div id =image-preview> image here!< / div>
<%= f.submit发送到数据库%>
<%end%>
这里< input type =image>
添加自js文件
var imageDiv = $(#image-preview);
imageDiv.html('< input type =imagename =img1style =margin-left:146pxid =spiro-imgsrc =''+ img +'/>' );
这一切都正常。
接下来我想把它发送到文件夹,但它不起作用。
这是我在控制器中的代码(从本网站引用 p>
图片 - 定义图片作为提交按钮。
其次你应该学会阅读的是日志。在屏幕截图中,你有params部分,并且没有 data_uri
键。
< input type ='file'... />
来上传。如果你想通过预览美容异步上传,你应该看看 jquery-file-upload
gem。 PS : type ='image'
是一个带图片的提交按钮。
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.
First what your should to do is read a docs: http://www.w3schools.com/Tags/att_input_type.asp
image - Defines an image as the submit button.
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 on jquery-file-upload
gem instead.
P.S.: type='image'
is a submit button with image.
这篇关于发送< input type ="图片">到服务器上的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!