1

基本上我已经创建了如下表:

类图像数据(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 列将以 blob 格式存储图像数据,

这样我就省了:

如果 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()

我的要求是序列化图像数据,以便我可以从 API 中获取。

但其显示错误如下:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

回溯(最近一次调用)文件“C:\Users\Python\ImageProcessApi\venv\Lib\site-packages\flask\app.py”,第 2464 行,调用中

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)
4

0 回答 0