Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Enorio opened this issue Dec 20, 2024 · 0 comments
Open

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

Enorio opened this issue Dec 20, 2024 · 0 comments

Comments

@Enorio
Copy link

Enorio commented Dec 20, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant