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

后端 未结 1 864
忘了有多久
忘了有多久 2021-01-04 12:58

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

相关标签:
1条回答
  • 2021-01-04 13:12

    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.

    0 讨论(0)
提交回复
热议问题