简体   繁体   中英

Ruby on Rails : upload file to server

I'm using Android device to upload file to server by using POST method. But I don't know how to make Rails handle this event. 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.

I have google and some results that tell me use additional plugin. Does exist any pure method just use rails only ? Please tell me.

Thanks :)

Rails can handle file uploads pretty easily. Here is the relevant guide that you should read: http://guides.rubyonrails.org/form_helpers.html

Here's a small snippet from the guide:

5.1 What Gets Uploaded

The object in the params hash is an instance of a subclass of 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM