robmarkcole / HASS-S3

Home Assistant integration for S3
Apache License 2.0
22 stars 13 forks source link

Add key prefix #3

Closed robmarkcole closed 3 years ago

robmarkcole commented 4 years ago

Add optional boolean key_prefix (default false) which will be prepended to the file name:

false: "S3:my_bucket/file.jpg" true: "S3:my_bucket/some/path/file.jpg"

submac commented 3 years ago

Hey, Thanks for this integration. Very helpful. Would you be able to add prefixes?

robmarkcole commented 3 years ago

@macieys any suggestions on if it should be:

submac commented 3 years ago

@robmarkcole, I would follow Ansible s3 module pattern if possible:

s3:
    bucket: mybucket
    object: /my/desired/key.txt
    src: /usr/local/myfile.txt

It's very clean and simple. https://docs.ansible.com/ansible/2.3/s3_module.html

robmarkcole commented 3 years ago

Right this is how minio integration is implemented also https://www.home-assistant.io/integrations/minio/

robmarkcole commented 3 years ago

Right this is how minio integration is implemented also https://www.home-assistant.io/integrations/minio/

submac commented 3 years ago

I see. Can we use key attribute to provide the whole path then? i.e.

key: filename.txt

or if user wants it under some prefix:

key: prefix/filename.txt
robmarkcole commented 3 years ago

Right now we are using the file_name as the key, which is a convenience but also lack flexibility.

s3_client.upload_file(Filename=file_path, Bucket=bucket, Key=file_name, ExtraArgs=extra_args)

In minio the key is required, and since this put service is most likely to be called from an automation maybe there is not much benefit from having the key inferred as we do currently. I am inclined to adopt the approach of minio, with both key and bucket required, so that automations can be used identically on both S3 and minio.

robmarkcole commented 3 years ago

Replacing with https://github.com/robmarkcole/HASS-S3/issues/11