ファイルを S3 に保存するための特定の構造パスを定義する必要があります。
例:
それ以外の
「バケット名/2010/12/23/127/43/2345/ファイル.jpg」
私は欲しい
「bucket_name/artists/elvis_presley/faceshot/100x100.jpg」
'bucket_name/books/the_black_cat/cover/180x280.jpg'
等
同様の質問を読みましたが、あまり聞き取れませんでした。
ありがとう。
ファイルを S3 に保存するための特定の構造パスを定義する必要があります。
例:
それ以外の
「バケット名/2010/12/23/127/43/2345/ファイル.jpg」
私は欲しい
「bucket_name/artists/elvis_presley/faceshot/100x100.jpg」
'bucket_name/books/the_black_cat/cover/180x280.jpg'
等
同様の質問を読みましたが、あまり聞き取れませんでした。
ありがとう。
Dragonfly 0.9.4 あたりから、モデルでこれを行うことができます。
class User < ActiveRecord::Base
image_accessor :image do
storage_path{ "users/#{self.user_type}/#{self.login_name" }
end
# ...
end
更新---
このようなことをするだけで、何か特別なものが本当に必要な場合は、以下のようにオーバーライドできます。より簡単な方法が組み込まれています:
some_image.store({:path => "images/some_identifier/the_name.jpg"})
それがバケットに保存されます。
元の投稿
これを config/initializers のファイル (たとえば、dragonfly.rb) に貼り付けます。
# Monkey patch for Dragonfly's S3 implementation
module Dragonfly
module DataStorage
class S3DataStore
def generate_uid(name)
# Replace this sucker for a better name
"#{Time.now.strftime '%Y/%m/%d/%H/%M/%S'}/#{rand(1000)}/#{name.gsub(/[^\w.]+/, '_')}"
end
end
end
end