@classmethod
def stream_file(cls, instance, field, file):
if not file:
return []
if isinstance(file, cls.stream_file_class):
return file
if isinstance(file, File):
return cls.stream_file_class(
instance, field, file, name=file.name, storage=cls.storage_class()
)
if isinstance(file, PlaceholderUploadedFile):
return cls.stream_file_class(
instance,
field,
None,
name=file.file_id,
filename=file.name,
storage=cls.storage_class(),
)
# This fixes a backwards compatibility issue with #507
# Once every application has been re-saved it should be possible to remove it
if "path" in file:
file["filename"] = file["name"]
file["name"] = file["path"]
return cls.stream_file_class(
instance,
field,
None,
name=file["name"],
filename=file.get("filename"),
storage=cls.storage_class(),
)