django-filer icon indicating copy to clipboard operation
django-filer copied to clipboard

How to get an "Image" instance from decoded image file data (base64)

Open ZhangChen199102 opened this issue 7 years ago • 4 comments

I'm using FilerImageField in my model (Recipe): photo = FilerImageField(null=True, blank=True, related_name="recipe_photo", )

I tried to upload a encoded image file data (base64) to server, then decode it and get a ContentFile object by using ContentFile(decoded_image_data).

The issue is I got an error in serializer.is_valid(): Exception Value: Cannot assign "<ContentFile: Raw content>": "Recipe.photo" must be a "Image" instance.

I'm wondering how can I get an 'Image' instance from decoded image data, or convert "ContentFile" to "Image".

ZhangChen199102 avatar Nov 23 '17 04:11 ZhangChen199102

did you ever find away to resolve this issue ?

kyale-mwendwa avatar Aug 18 '18 10:08 kyale-mwendwa

Looking through these old tickets I get the feeling Divio doesn't have the resources to address them.

stuaxo avatar Oct 25 '19 15:10 stuaxo

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 28 '22 18:07 stale[bot]

Hey stalebot this is still an issue.

stuaxo avatar Jul 28 '22 20:07 stuaxo

you need to create a record with Filer.Image field and add your ContentFile to the file attribute then use that Filer.Image instance and it will work:

example that works with my code:

        file = request.FILES["file"]
        contract = self.get_object()

        filer_file = File.objects.create(
            file=DjangoFile(file, file.name),
            name=file.name,
            owner=request.user,
        )
        document = ContractDocument.objects.create(
            file=filer_file,
            user=request.user,
            contract=contract,
            status="draft",
        )

abdul-hamid-achik avatar Sep 26 '22 20:09 abdul-hamid-achik

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Dec 25 '22 20:12 stale[bot]

This will now be closed due to inactivity, but feel free to reopen it.

stale[bot] avatar Jan 22 '23 20:01 stale[bot]