开发者

Removing default file names in Django-Storages S3

开发者 https://www.devze.com 2023-03-24 18:52 出处:网络
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)

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?


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号