如何从“ActionDispatch :: Http :: UploadedFile”实例中检索FileBlob? [英] How to retrieve a FileBlob from 'ActionDispatch::Http::UploadedFile' instance?
问题描述
我用'remotipart'gem将文件异步上传到服务器端。传递给服务器端的实例是'UploadedFile'。
Rails API提到类的所有方法(如read(),open())和属性,但我不知道如何检索文件,并将其存储在数据库?
谷歌搜索使我没有教程使用这个类。
这是很少记录,因为大多数人使用宝石处理文件上传。
对象称为文件
。你可以用下面的方法确定路径:
file.tempfile.to_path.to_s
您应该移动该文件,因为它存储在 / tmp
中,可能会被系统删除。你可以使用 FileUtils.mv
方法。然后,您可以将文件的新路径添加到数据库。
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.
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.
这篇关于如何从“ActionDispatch :: Http :: UploadedFile”实例中检索FileBlob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!