Suppose i have this file in s3 bucket:
s3://qq-dag/production/special-db/xx.gz
I want now that somebody would be able to send me this path and i would automatically use this file path in order to send the file itself in a post request i make.
The solution i thought about is first downloading it to local and then somehow using my local file path to send in post request. Could it work? Anyone can post an example of how i do it?
i tried something like this but i keep getting errors for every solution i try any variation of this code:
file = r'C:\Users\jhon.king\files\xx.gz'
bucket = 'qq-dag/production/special-db'
key='xx.gz'
s3client = boto3.client('s3')
s3client.download_file(bucket, key, file)
//now post request part
files=[
('file',('xx.gz',ocpen(''r'C:\Users\jhon.king\files\xx.gz,'rb'),'text/gz'))
]
headers = {
'X-Atlassian-Token': 'nocheck',
'Authorization': 'Basic Ymyb3dpdHo6kkczEyMzQ=',
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
I am sure i somehow misplay with the bucket or file name parts . Any one can help me?
i tried this for download based on an answer bellow i keep on getting error
import os
prefix = 'user/mynew-research'
file = "mymyjira.gz"
#s3.Bucket(bucket).download_file(f'{prefix}/{file}', file)
AWS_KEY_ID = "kUvRWN8xabRdg++lUP84A3g"
AWS_ACCESS_KEY = 'AKIAJPQ'
bucket = 'my-research'
s3=boto3.resource(
service_name='s3',
region_name='us-east-1',
aws_access_key_id=AWS_KEY_ID,
aws_secret_access_key=AWS_ACCESS_KEY
)
s3.Bucket(bucket).download_file(f'{prefix}/{file}', file)
ClientError: An error occurred (400) when calling the HeadObject operation: Bad Request