0

I am saving 4 images from the user (maybe it will be null). I do not want to save the images in a directory or folder,I need to save the images in db(mysql). The 'form.save' is working and after looking in db the blob is present but there is no data in it.Not only that the null is displaying as blob!

forms.py

  class ClientCreateForm(ModelForm):
    photo = forms.ImageField(required=False)
    signature = forms.ImageField(required=False)
    poi_image = forms.ImageField(required=False)
    poa_image = forms.ImageField(required=False)

model.py

class Client(models.Model):
       
    photo = models.ImageField(db_column='PHOTO', blank=True, null=True)  
    signature = models.ImageField(db_column='SIGNATURE', blank=True, null=True)  
    poi_image = models.ImageField(db_column='POI_IMAGE', blank=True, null=True)  
    poa_image = models.ImageField(db_column='POA_IMAGE', blank=True, null=True)   

views.py

def client_create_view(request):
  if request.method == 'POST':
     form = ClientCreateForm(request.POST)
        if form.is_valid():
          form.save()
        else:
          pass




          

2 Answers 2

1

According to Django documentation, this is not how ImageField and FileField works, they save in MEDIA_ROOT and add the path to the database. You should use BinaryField instead.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes, you can for sure.
How to save it as Binary, I tried it but could not do it . I have have asked it as other question
You have to handle the saving manually, and don't depend of the form saving it
0

In PostgreSQL, it should be "BYTEA" instead of "BLOB".

1 Comment

Good to know , Wish I get what I am seeking for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.