Save files using paperclip via API

我是研究僧i 提交于 2019-12-09 06:07:01

问题


I'm using paperclip to manage uploads, backed onto S3 via Fog. It works well.

I'm trying to take attachments out of emails and save them via paperclip (using the same model etc). Email are parsed by an external service and POSTed to my app, including the attachments. I'm receiving the file itself fine, but I can't work out how to save it using paperclip. The post gives me an object of type ActionDispatch::Http::UploadedFile.

I took a look at the below, but this involves creating a new File object. I'm not sure this is what I want... How should I do it?

Saving files using Paperclip without upload


回答1:


If you already have the UploadedFile, you can just set the virtual attribute Paperclip gives you to that.

So, if you had a params[:file], and a model with has_attached_file :file, you should be able to just do @obj.file = params[:file]; @obj.save.



来源:https://stackoverflow.com/questions/8228188/save-files-using-paperclip-via-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!