3
我有一個數據庫,超過200萬條記錄。每個記錄都包含一個圖像的URL,我需要下載並存儲到AWS S3。從MongoDB獲取大數據的最佳方法
與其一次下載一個,然後一次上傳一個,有沒有更好的方法來處理這個問題?
我使用Python,因此pymongo目前。
for item in itemsCursor:
download_image(item['imageurl')
def download_image(item):
name = 'example.jpg'
response = requests.get(url)
img = Image.open(StringIO(response.content))
img.save('temp.jpg', "JPEG")
s3.meta.client.upload_file('temp.jpg', 'bucket', name)
grequests https://pypi.python.org/pypi/grequests –