[Answered ]-How do I save images directly into a MySQL database as a BLOB using django? These images are uploaded dynamically through the django admin panel?

1👍

Create TextField in Model encode the file to base64 & Store in it.

import base64

from django.db import models

class Blob(models.Model):

    file = models.TextField(
            db_column='data',
            blank=True)

    def set_data(self, data):
        self.file = base64.encodestring(data)

    def get_data(self):
        return base64.decodestring(self.file)

    data = property(get_data, set_data)

Leave a comment