0
votes

Technologies:

  • Python3
  • Boto3
  • AWS

I have a project built using Python3 and Boto3 to communicate with a bucket in Amazon S3 service.

The process is that a user posts images to the service; these' images are uploaded to an S3 bucket, and can be served through amazon cloudfront using a hashed file name instead of the real file name.

Example:

  • (S3) Upload key: /category-folder/png/image.png
  • (CloudFront) Serve: http://d2949o5mkkp72v.cloudfront.net/d824USNsdkmx824

I want to file uploaded to S3, appear as hash number as file name in cloudfront server.

Does anyone have knowledge that makes S3 or cloudfront automatically convert and publish a file-name to a hash name.

1
The cloudfront cdn just provide the urn for the contents, and appear as url ... so , what is your problem? - mootmoot
I don't want to use the full path + filename, I want to use a hashed version (like spotify for example) - is this possible? as in built in, or do I have to hash it myself? - Julian Camilleri
@belthazorNv you have to hash it yourself - Mark B
I just edit your question , check whether it is appropriate server your needs. p/s: I have similar requirement, I just wrote a wrapper to do the conversion. Because there is no "use SHA256 hash as file name option" , nor with auto-zip. etc - mootmoot
I see... that pretty much sums it up. - Thank you guys - Julian Camilleri

1 Answers

0
votes

In order to suffice my needs I created the fields needed to maintain the keys (to make them unique; both on S3 and in my mongodb)

Fields:

original_file_name = my_file_name
file_category = my_images, children, fun 
file_type = image, video, application
key = uniqueID

With the mentioned fields; then one can check if the key exists by simply searching for the key, the new file_name, the category, and the type; if it exists in the database then file exists.

To generate the unique id:

def get_key(self):
    from uuid import uuid1
    return uuid1().hex[:20]

This limits the ID to the length of 20 characters.