5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

railsで画像を扱う

5
Posted at

urlからs3に画像をアップする

該当のファイルのcontent typeを知る

res = Net::HTTP.start(uri.host, uri.port) do |http|
  http.get(uri.path, {'User-Agent' => UrlConcern::USER_AGENT})
end
res.content_type

高さと幅を知る

res = Net::HTTP.start(uri.host, uri.port) do |http|
  http.get(uri.path, {'User-Agent' => UrlConcern::USER_AGENT})
end
magick = Magick::Image.from_blob(res.body).shift
width = magick.columns
height = magick.rows

s3にアップする

option = {
  'Content-Type' => res.content_type,
  'Content-Length' => res.body.length,
  'x-amz-acl' => 'public-read',
  'Cache-Control' => "max-age=#{24*60*60*7}, private, must-revalidate",
}

s3_storage.put_object(s3_bucket, path, body, option)
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?