如何使用python-restapi序列化blob数据?
基本上,我创建了如下表: 类ImageData(db.Model): 图像列将以blob格式存储图像数据 这样我就节省了: 如果request.file中有“image”:如何使用python-restapi序列化blob数据?,python,flask,flask-sqlalchemy,flask-restful,flask-marshmallow,Python,Flask,Flask Sqlalchemy,Flask Restful,Flask Marshmallow,基本上,我创建了如下表: 类ImageData(db.Model): 图像列将以blob格式存储图像数据 这样我就节省了: 如果request.file中有“image”: imagedata = request.files['image'] imageD = imagedata.read() image = ImageData( uname = request.form['uname'], fname = request.
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)
def\uuuu调用(self、environ、start\u响应):
“”“WSGI服务器调用Flask应用程序对象作为
这个调用:meth:`WSGI_app`,它可以是
包装到应用中间件
返回self.wsgi_应用程序(环境,启动响应)
定义报告(自我):
返回“%”(self.\u class.\u.\u名称\u,self.name)
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)