- Newest
- Most votes
- Most comments
Your code is saying that the body (the contents of file file to upload) is the string /tmp/csv_file.csv
. The Body
parameter requires "bytes or a seekable file-like object" as per the documentation.
Perhaps you're looking for the upload_file method?
Another way would be to use the StringIO
library in Python to build the file in memory, then pass that to put_object
as the Body
. Depends on how much memory the function has; and you may also want to see how much space /tmp
has too depending on the size of the query result from the database.
Hello.
Looking at this, it looks like put_object needs to specify the data rather than the file name to be uploaded.
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3/client/put_object.html
So, I thought that if I want to upload the file as is, I need to write the code as follows.
with open('/tmp/csv_file.csv', 'rb') as csvfile:
csv_content = csvfile.read()
s3client.put_object(Bucket=s3bucketname, Body=csv_content, Key='csv_file.csv')
Alternatively, I think it is possible to use upload_file() and do the following.
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3/client/upload_file.html
s3client.upload_file(Filename='/tmp/csv_file.csv', Bucket=s3bucketname, Key='csv_file.csv')
Relevant content
- asked a year ago
- asked 3 years ago
- Accepted Answerasked 2 months ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated a month ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago