ユーザーが画像をアップロードするには 2 つの方法があります。1 つは単純な HTML フォームを使用する方法で、もう 1 つは Aurigma という iPhone アプリを使用する方法です。Paperclip を使用して画像を処理し、S3 に保存します。Aurigma でアップロードされた画像は、間違った content-type を持つことになり、アプリケーションとして開く原因となります。
私は2つの解決策を試しました:
before_save :set_content_type
def set_content_type
self.image.instance_write(:content_type,"image/png")
end
と:
before_post_process :set_content_type
def set_content_type
self.image.instance_write(:content_type, MIME::Types.type_for(self.image_file_name).to_s)
end
両方のソリューションが無視されているようです。
paperclip バージョン 3.0.2、Aurigma バージョン 1.3 を使用して、iPhone からスクリーンショットをアップロードしています。これは私のペーパークリップ構成です:
has_attached_file :image, {
:convert_options => { :all => '-auto-orient' },
:styles => {
:iphone3 => "150x150",
:web => "300x300"
},
:storage => :s3,
:bucket => ENV['S3_BUCKET'],
:s3_credentials => {
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET']
},
:path => "/pictures/:id/:style.:extension",
:url => "/pictures/:id/:style.:extension"}
}