【发布时间】:2011-07-14 04:39:01
【问题描述】:
更新:我已经切换到 CarrierWave(终于让它工作了),所以虽然我仍然很感激这个问题的答案,但如果它们真的有效,我将无法尝试因为我已经从我的代码中完全删除了 DM-Paperclip。
你好,
我正在使用 DataMapper 开发一个 Sinatra-webapp,现在正在寻找使用 S3 作为存储添加一些上传功能。我已经尝试过CarrierWave,但我无法让它工作,所以现在我正在尝试 dm-paperclip。这就是我现在拥有的:
型号:
class Article
include DataMapper::Resource
include Paperclip::Resource
property :id, Serial
property :created_at, DateTime
property :updated_at, DateTime
property :title, String
property :body, Text
has_attached_file :screenshot,
:storage => :s3,
:s3_credentials => {
:access_key_id => 'my-access-key-id',
:secret_access_key => 'my-secret_access-key',
:bucket => 'my-bucket'
},
:styles => {
:medium => "300x300>",
:thumb => "100x100>"
}
end
控制器:
post '/articles/create' do
@article = Article.new
@article.title = params[:title]
@article.body = params[:body]
@article.screenshot = params[:screenshot]
begin
@article.save
rescue DataMapper::SaveFailureError => e
puts "Error saving article: #{e.to_s} validation: #{@article.errors.values.join(', ')}"
rescue StandardError => e
puts "Got an error trying to save the article #{e.to_s}"
end
redirect '/articles'
end
然而,当我创建一篇新文章时,它并没有将任何内容保存到我的 S3 存储桶中,而且我也没有收到任何错误。
任何想法我做错了什么?
【问题讨论】:
标签: ruby amazon-s3 paperclip sinatra datamapper