【问题标题】:Removing default file names in Django-Storages S3删除 Django-Storages S3 中的默认文件名
【发布时间】:2011-08-03 15:10:44
【问题描述】:

我将 django-storages 与 amazon S3 一起使用,并通过以下方式上传图像文件:

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

但是,当文件上传到 S3 时,它会在末尾附加原始文件名。我该如何摆脱它并用一些随机哈希代替它?

【问题讨论】:

    标签: python django filefield django-storage


    【解决方案1】:

    Supply a callable instead of a string to upload_to。可调用对象将传递正在保存的实例和文件名,并且必须返回完整路径,包括文件名——因此您可以选择不使用原始文件名。 (不过,您必须使用datetime.date.today() 自己致电strftime

    【讨论】:

      猜你喜欢
      • 2015-06-05
      • 1970-01-01
      • 1970-01-01
      • 2016-03-13
      • 2019-07-05
      • 2012-07-14
      • 2014-09-15
      • 1970-01-01
      • 2013-12-29
      相关资源
      最近更新 更多