Skip to content

Input *.png of type: InMemoryUploadedFile is not supported. #322

Description

@Enorio

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):
Screenshot from 2024-12-20 16-59-47
Screenshot from 2024-12-20 17-00-30

What am I missing? Can't I use the same InMemoryUploadedFile for 2 uploads?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions