1

Basically I have created the table as below:

class ImageData(db.Model):

id = db.Column(db.Integer, primary_key = True)
uname = db.Column(db.VARCHAR(20), nullable = True, unique=True)
fname = db.Column(db.VARCHAR(20), nullable = True)
lname = db.Column(db.VARCHAR(20), nullable = True)
email = db.Column(db.VARCHAR(50), nullable = True, unique=True)
image = db.Column(db.LargeBinary, nullable=True)

image column will store the image data in blob format,

this way I am saving:

if 'image' in request.files:

        imagedata = request.files['image']
        imageD = imagedata.read()
    image = ImageData(
        uname = request.form['uname'],
        fname = request.form['fname'],
        lname = request.form['lname'],
        email = request.form['email'],
        image = imageD
    )
    db.session.add(image)
    db.session.commit()

My requirement is to serialize the image data so that I can get that from API.

But its showing error like below: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

Traceback (most recent call last) File "C:\Users\Python\ImageProcessApi\venv\Lib\site-packages\flask\app.py", line 2464, in call

def __call__(self, environ, start_response):
    """The WSGI server calls the Flask application object as the
    WSGI application. This calls :meth:`wsgi_app` which can be
    wrapped to applying middleware."""
    return self.wsgi_app(environ, start_response)

def __repr__(self):
    return "<%s %r>" % (self.__class__.__name__, self.name)

0 Answers0