beasone
beasone

Reputation: 1095

python boto3, upload file to s3 return False but no exception

try:
        
        if s3.meta.client.upload_file(fileLocation, bucket_name, objectName) is True:
            print("Upload log file to s3 bucket")
        else:
            print('Upload file to s3 bucket failed')
            return False
    except s3.exceptions:
        print("known error occured")
    except ClientError as e:
        print("Unexpected error: %s" % e)

I run this code but then it prints Upload file to s3 bucket failed , no exception happens so I have no idea why it failed. The s3 bucket exists since I got the bucket_name from list all existing buckets.

Upvotes: 0

Views: 1345

Answers (1)

A.B
A.B

Reputation: 20455

s3.meta.client.upload_file doesn't return anything as per documentation, so you have None and it falls into else, have you checked that file in S3?

Also، check if you have lesding slash (/) in your path, your file may end in a newly crested folder 'uploads' in the bucket.

Upvotes: 1

Related Questions