liormizr / s3path

s3path is a pathlib extension for AWS S3 Service
Apache License 2.0
206 stars 39 forks source link

Metadata #83

Closed MaartenUreel closed 3 years ago

MaartenUreel commented 3 years ago

Is it possible to configure metadata when uploading / creating a file this way?

liormizr commented 3 years ago

Hi @MaartenUreel Do you mean configure metadata specifically per file? Or per every call to upload / create a file?

MaartenUreel commented 3 years ago

I use S3Path in a lambda function to create one file, so it doesn't matter for me. Any implementation is fine :)

Specifically for that file would be the cleanest I guess.

I need to add 'ContentType' => 'text/html',

liormizr commented 3 years ago

Personally I would have done something like this:


from s3path import S3Path, register_configuration_parameter

# All files (Keys) will be created or updated with ContentType='text/html'
register_configuration_parameter(S3Path('/'), parameters={'ContentType': 'text/html'})

def lambda_handler(event, context):
    ...

Is that good?

liormizr commented 3 years ago

@MaartenUreel did my comment helped you?

MaartenUreel commented 3 years ago

Hello

I ended up writing the file with just boto3. But your approach would have helped probably indeed too, altough it's a bit counter-intuitive to set this as default instead of on file-level...

Maybe a nice addition for a future version :)

cooperlees commented 9 months ago

Howdy - Seems bandersnatch has hit this writing to S3. Is there any plans to support correct Content-Type setting for known files that need it or do you want to keep it the consumer/library user sets it? It shouldn't be a big change to bandersnatch to supply the ContentType on files here.

As someone who has hardly used S3, can an existing file's ContentType be checked and changed? I feel we'll need to create a bandersnatch run to go and check and set the content type on all .html and .json files bandersnatch has uploaded to s3 correctly due to us having this bug ... How would you recommend doing that?