如何在django save方法的Overwrite storage class中使用回调方法?

时间:2019-02-04 15:04:11

标签: python django overwrite django-storage

当我尝试调用覆盖方法的save方法时,我想调用一个回调方法,但是似乎不起作用。

下面是我的代码。

class OverwriteStorage(Storage):

def save(self, name, content, max_length=None, callback=None):
        """
        Save new content to the file specified by name. The content should be
        a proper File object or any Python file-like object, ready to be read
        from the beginning.

        This method is modified to take care of callbacks for S3 storage class of amazon.
        So that user specific callback can be accommodated.
        :param name: name of the file.
        :param content: content of the file
        :param max_length: max length of the file.
        :param callback: callback method.
        :return:
        """

        # Get the proper name for the file, as it will actually be saved.
        if name is None:
            name = content.name

        if not hasattr(content, 'chunks'):
            content = File(content, name)

        name = self.get_available_name(name, max_length=max_length)

        return self._save(name, content, callback=callback)

但是当我试图称呼它时:

file.file_location.save(name_of_the_file, File(open(str(name_of_the_file), 'r')),callback=ProgressPercentageUpload(name_of_the_file, size_of_the_file))

它抛出以下错误:

TypeError: save() got an unexpected keyword argument 'callback'

我在做错什么吗?

感谢您的帮助。

0 个答案:

没有答案