boto3 upload to s3 not giving errors, but files do not show up in bucket

0

Just as the title says. Initially, I attempted using the sample code given from the docs linked below, with the exception that I passed my access key and secret key when creating the client object.

https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-uploading-files.html

I was using driver code that printed the file name and 'success' when the function returned true. All files were being printed with 'success.' But when I checked my bucket, no uploads appeared.

On the off chance it was something wrong in the function, I changed my code to just use

 response = s3_client.upload_file(file_name, bucket, file_name)

directly in the driver and without the rest of the function, still the code ran without errors, but no uploads appeared in my bucket.

In the shell I logged in with the client and was able to successfully produce a list of my buckets, so I know it's connecting and the access keys are working in that sense.

All I can think is maybe I'm missing some formatting thing with my bucket names? I'm just using the plain text name as a string, for example 'mybucket1234.' Do I need to give it the full url?

Edited by: lwaxana on Feb 16, 2020 7:46 AM

lwaxana
질문됨 4년 전1524회 조회
1개 답변
0

I was having the same problem with code adapted from https://boto3.amazonaws.com/v1/documentation/api/latest/guide/s3-uploading-files.html

s3_client.upload_file completed without an exception but the file was not visible in the S3 web console or via "aws s3 ls s3://bucket-name"

The issue was with these lines:

    if object_name is None:
        object_name = file_name

file_name is actually a file path and the upload seems to silently fail if it contains path separators. The workaround is either to always provide an object_name or change it to:

    if object_name is None:
        object_name = file_name.split(os.path.sep)[-1:][0]
답변함 4년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠