Replies: 2 comments
-
I don't have a simple answer for you, but here are some hints. If you're doing a multipart upload, I think you need to pass ContentType as multipart_upload_kwargs. It looks like there's a ContentType parameter there (https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.create_multipart_upload) and smart_open "should" pass it correctly. Have a look at this howto section for more info: https://github.com/RaRe-Technologies/smart_open/blob/develop/howto.md#how-to-pass-additional-parameters-to-boto3 If you're doing a single part upload, it doesn't look like smart_open supports passing the content type at all. It uses (https://github.com/RaRe-Technologies/smart_open/blob/59d3a6079b523c030c78a3935622cf94405ce052/smart_open/s3.py#L821) put_object which seems to accept ContentType, but smart_open does not accept or pass that parameter along. This should be easy enough to implement in a PR, if you're interested. Have a look through the links above, dig around a little bit, and let me know if you figure anything out. |
Beta Was this translation helpful? Give feedback.
-
Even using the direct S3 calls, I was only ever able to set a SECOND Metadata key:value pair (below), so I've given up and will use the copy-in-place workaround. |
Beta Was this translation helpful? Give feedback.
-
I'm using smart_open to write an HTML file to S3, but the default ContentType is binary/octet-stream.
How can I set my file's mime type to text/html as I write it?
Perhaps with something like transport_params={'ContentType': "text/html"} ?
Currently my work around is:
s3_filename = "s3://{}/{}".format(bucket_name, key)
# Adding transport_params={'ContentType': "text/html"} did not work here
with open(s3_filename, "wb") as f:
f.write(...)
# Copy newly created .html file IN PLACE just to change ContentType to text/html from binary/octet-stream
s3 = boto3.resource("s3")
s3_object = s3.Object(bucket_name, key)
s3_object.copy_from(CopySource={'Bucket': bucket_name, 'Key': key},
MetadataDirective="REPLACE",
ContentType="text/html")
Beta Was this translation helpful? Give feedback.
All reactions