aliyun / django-oss-storage

Django storage backends for AliCloud OSS.
MIT License
145 stars 67 forks source link

Django 内部的 Storage.save 方法被覆盖,但丢掉了文件名防冲突的行为 #21

Closed wonderbeyond closed 4 years ago

wonderbeyond commented 6 years ago

OssMediaStorageOssStaticStorage 两个 Storage 子类中,save 方法被覆盖了,只是简单地调用了 OssStorage_save 方式,而无视了 django.core.files.storage.Storage.save 提供的文件名放冲突行为。


建议 OssMediaStorageOssStaticStorage 就不要定义 save 方法了,直接从 django.core.files.storage.Storage 继承就好,它会自动找一个不冲突的名字,然后调用子类的 _save 方法。

wonderbeyond commented 6 years ago

我直接在自己应用工程里面定义了一个子类找回了 Django 的默认行为:

myproject/storages.py:

from django_oss_storage.backends import OssStorage

class OssMediaStorage(OssStorage):
    def __init__(self, location='media', **kwargs):
        self.location = location
        super(OssMediaStorage, self).__init__(**kwargs)

settings.py:

DEFAULT_FILE_STORAGE = 'mysite.storages.OssMediaStorage'
favoyang commented 6 years ago

Duplicated with https://github.com/aliyun/django-oss-storage/issues/17.

wonderbeyond commented 6 years ago

So sorry

huiguangjun commented 4 years ago

fixed in version 1.1.1