django-filer
django-filer copied to clipboard
How to get an "Image" instance from decoded image file data (base64)
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".
did you ever find away to resolve this issue ?
Looking through these old tickets I get the feeling Divio doesn't have the resources to address them.
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.
Hey stalebot this is still an issue.
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",
)
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.
This will now be closed due to inactivity, but feel free to reopen it.