Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve a FileBlob from 'ActionDispatch::Http::UploadedFile' instance?

I have used 'remotipart' gem to upload files asynchronously to server side. The instance passed to the server side is of 'UploadedFile' .

The Rails API mentions all the methods( like read(), open() ) and attributes for the class, however I am not sure how to retrieve the File and store it on the database?

Googling took me to no tutorials using this class.

like image 392
Nitish Upreti Avatar asked Mar 03 '12 08:03

Nitish Upreti


1 Answers

This is rarely documented because most people use gems to handle file uploads.

Let's say your object is called file. You could determine the path using this:

file.tempfile.to_path.to_s

You should move the file because it's stored in /tmp and might be deleted by the system. You can use FileUtils.mv method for this. Then you can add the new path of the file to the database.

like image 114
davidb Avatar answered Oct 20 '22 03:10

davidb