4

I'm using django-storages with amazon S3, and uploading image files with:

models.ImageField(upload_to="img=%Y-%m-%d", max_length=256, blank=True, null=True)

When the files are uploaded to S3 however, it has the original file name attached at the end. How do I get rid of that and replace it, with say some random hash instead?

ahalbert
  • 474
  • 1
  • 6
  • 15

1 Answers1

3

Supply a callable instead of a string to upload_to. The callable will be passed the instance being saved, and the filename, and will have to return the full path, including the filename -- so you can choose not to use the original filename. (You'll have to call strftime yourself with datetime.date.today(), however).

Ismail Badawi
  • 36,054
  • 7
  • 85
  • 97