-
Notifications
You must be signed in to change notification settings - Fork 146
Description
I'm using Django and DjangoRestFramework, and I have a model with a FileField attribute
I have two ways of creating this model. Both receive the same values, but one of them raises Input foo.png of type: <class 'django.core.files.uploadedfile.InMemoryUploadedFile'> is not supported.
Giving my example:
class Foo:
logo = models.ImageField(upload_to="logos/", null=True")
bar = models.ForeignKey("bar.Bar", null=True)
class Bar:
file = models.FileField(validators=[FileExtensionValidator(['jpeg', 'jpg', 'jpe', 'png', 'mov', 'mpeg4', 'avi', 'mp4', 'wmv'])])
I can through the respective endpoint, create Bar and upload to S3, no problem
In the Foo endpoint (I'm updating Foo), I want to upload the logo, but also create the bar. I'm overriding the serializer to do this.
def update(self, instance, validated_data):
logo = validated_data.get("logo", None)
if logo:
bar = Bar.objects.create(file=logo)
validated_data["bar"] = bar
return super().update(instance, validated_data)
With this, I get Input foo.png of type: <class 'django.core.files.uploadedfile.InMemoryUploadedFile'> is not supported.
Following the stacktrace, It starts in the return super().update(instance, validated_data)
and ends in the UploadSubmissionTask _get_upload_input_manager_cls
From what I see in the debug, the fileobj is the same for both requests, with a slight difference (the second image is with the Foo endpoint):
What am I missing? Can't I use the same InMemoryUploadedFile for 2 uploads?