I'm trying to create an endpoint that allows uploading a picture to my S3 bucket, everything seems to work correctly when uploading PNG images (JPEG images do not work but that's an issue for another time), however if I try to visualize the uploaded image in the browser it just shows as an black page with a little grey square in the middle. If I check the Metadata of the uploaded file, the Content-Type of S3 is correctly set to image/png, so I don't know what may be going on.
I pass the base64 image as multipart form-data and then decode it with
for part in multipart_data.parts:
file = base64.b64encode(part.content).decode()
after that I use mimetypes guess_all_extensions() function to get the extension of the file. My uploading code looks like the following:
s3_client = boto3.client("s3")
default_bucket = "some_bucket"
try:
s3_client.put_object(
Body=file,
Bucket=default_bucket,
Key=file_key,
ContentType=content_type
)
except botocore.exceptions.ClientError as error:
print(f"error: {error}")
The image opened from the s3 management console looks like the folowing:
1
question from:
https://stackoverflow.com/questions/65942399/png-image-not-uploading-correctly-to-aws-s3-with-python-and-boto3 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…