0
0

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 1 year has passed since last update.

pythonで他のサイト上の画像を直接s3に保存する

Posted at

環境は以下です。

$ python3 --version
Python 3.10.4

コードは以下です。

import requests
import boto3

# s3の設定
BUCKET_NAME = 'your-bucket-name'
s3 = boto3.resource('s3')
bucket = s3.Bucket(BUCKET_NAME)

# 画像を直接保存
url = 'https://hogehoge.jpg'
res = requests.get(url, stream=True)
bucket.upload_fileobj(res.raw, "foo/bar/baz")

AWS EC2インスタンス上から実行するとして、
IAMロールでs3へのアクセス権限を設定したものをアタッチしておくか、aws configureから認証情報の設定周りは済んでいる前提です。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?