gpt4 book ai didi

ruby - 如何使用 Sinatra、Datamapper、DM-Paperclip 和 S3?

转载 作者:数据小太阳 更新时间:2023-10-29 08:01:52 27 4
gpt4 key购买 nike

更新:我已经切换到 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

Controller :

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 存储桶中,我也没有收到任何错误。

知道我做错了什么吗?

最佳答案

嘿!请试试我的 fork :https://github.com/solnic/dm-paperclip它包含许多补丁,这些补丁修复了 S3 的一些问题。我将在一两个月内发布它。

关于ruby - 如何使用 Sinatra、Datamapper、DM-Paperclip 和 S3?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5285085/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com