Created
October 1, 2020 09:38
-
-
Save a6kme/00f8a82201214b614465fe3d091ed8d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def download_and_upload_to_s3(request_url, s3_file_key): | |
manager = urllib3.PoolManager() | |
try: | |
response = manager.request('GET', request_url) | |
except (NewConnectionError, MaxRetryError): | |
return False | |
s3_client = boto3.client('s3') | |
try: | |
s3_client.put_object( | |
Body=BytesIO(response.data), | |
Bucket=S3_BUCKET, | |
Key=f'benchmark_image_processing/{s3_file_key}', | |
ContentType=response.headers['Content-Type'], | |
ContentDisposition=response.headers['Content-Disposition'], | |
) | |
except (ClientError, KeyError) as e: | |
return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment