基本上,我创建了如下表:
类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)
图像列将以blob格式存储图像数据
这样我就节省了:
如果request.file中有“image”:
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”编解码器无法解码位置0中的字节0xff:无效的开始字节
回溯(最近一次呼叫最后一次) 文件“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)
目前没有回答
相关问题 更多 >
编程相关推荐