0
我试过ImageField(upload_to='', storage=S3MediaStorage)
,当save()
被调用时,它给出错误TypeError: get_valid_name() missing positional argument: 'name'
。但是,如果我忽略storage=
并使用DEFAULT_FILE_STORAGE
存储桶,则可以完美地工作。Django - 如何上传到特定的S3存储桶?
S3MediaStorage
:
class S3MediaStorage(S3BotoStorage):
def __init__(self, *args, **kwargs):
kwargs['bucket'] = getattr(settings, 'AWS_BUCKET_MEDIA')
super(S3MediaStorage, self).__init__(*args, **kwargs)
models.py
:
class Image(models.Model):
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
visible = models.BooleanField(default=False)
author = models.ForeignKey(settings.AUTH_USER_MODEL, models.CASCADE)
caption = models.CharField(max_length=254, blank=True)
image = models.ImageField(upload_to='', storage=S3MediaStorage)
def __str__(self):
return str(self.created)
我在做什么错?我应该使用完全不同的方法将文件上传到非默认存储桶吗?