【问题标题】:Process Uploaded Image Before Saving Through Paperclip在通过回形针保存之前处理上传的图像
【发布时间】:2013-09-02 17:06:29
【问题描述】:

我有一个表格可以让我上传图片。然后在控制器中,我获取上传的图像并在图像上运行一些进程。处理完图像后,我将其存储在/public/ 文件夹中。

我想把那张图片交给回形针保存。有人可以告诉我如何实现这一目标。

谢谢

【问题讨论】:

标签: ruby-on-rails paperclip dropbox-api


【解决方案1】:

你可以这样做:- 我假设这个模型。

class SomeModel < ActiveRecord::Base
has_attached_file :avatar
end

在你的控制器中

def someaction
 a = SomeModel.new
 #you did your processing here and saved it in public folder
 # if you have file object, you can use it or 
 f = File.open((File.join(Rails.root, "public", filename)))
 a.avatar = f
 a.save
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-02
    • 2016-03-31
    • 1970-01-01
    • 2016-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多