[英]Ruby on Rails : upload file to server
I'm using Android device to upload file to server by using POST method. 我正在使用Android设备通过POST方法将文件上传到服务器。 But I don't know how to make Rails handle this event.
但我不知道如何让Rails处理这个事件。 It means, after Android device sends file to server by method POST by the link :
http://localhost/upload_file
, rails server can handle this event, and put this file into database, for example. 这意味着,Android设备通过方法POST通过链接将文件发送到服务器后:
http://localhost/upload_file
,rails服务器可以处理此事件,并将此文件放入数据库中。
I have google and some results that tell me use additional plugin. 我有谷歌和一些结果告诉我使用额外的插件。 Does exist any pure method just use rails only ?
是否存在任何纯方法只使用rails? Please tell me.
请告诉我。
Thanks :) 谢谢 :)
Rails can handle file uploads pretty easily. Rails可以非常轻松地处理文件上传。 Here is the relevant guide that you should read: http://guides.rubyonrails.org/form_helpers.html
以下是您应阅读的相关指南: http : //guides.rubyonrails.org/form_helpers.html
Here's a small snippet from the guide: 这是指南中的一小段:
5.1 What Gets Uploaded
5.1什么上传
The object in the params hash is an instance of a subclass of IO.
params散列中的对象是IO的子类的实例。 Depending on the size of the uploaded file it may in fact be a StringIO or an instance of File backed by a temporary file.
根据上载文件的大小,它实际上可能是StringIO或由临时文件支持的File实例。 In both cases the object will have an original_filename attribute containing the name the file had on the user's computer and a content_type attribute containing the MIME type of the uploaded file.
在这两种情况下,对象都将具有original_filename属性,该属性包含文件在用户计算机上具有的名称,以及包含上载文件的MIME类型的content_type属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.