如何使用flask上传图像并将其存储在couchdb中? [英] How to upload an image with flask and store in couchdb?

查看:103
本文介绍了如何使用flask上传图像并将其存储在couchdb中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上一个问题询问如何从ouchdb中检索附件并将其显示在flask应用程序中.

A previous question asks how to retrieve at attachment from couchdb and display it in a flask application.

这个问题询问如何执行相反的操作,即如何使用flask上传图像并将其另存为couchdb附件.

This question asks how to perform the opposite, i.e. how can an image be uploaded using flask and saved as a couchdb attachment.

推荐答案

看看 FileField api文档 .在那里,您可以使用流方法来访问上载的数据.除了可以使用示例中的save方法之外,您还可以访问流中的字节,对base64进行编码并将其另存为例如ouchdb中的附件.使用 put_attachment .另外,FileStorage api文档建议您可以使用read()检索数据.

Take a look at the FileField api docs. There you have a stream method giving you access to the uploaded data. Instead of using the save method as in the example you can access the bytes from the stream, base64 encode it and save as an attachment in couchdb, e.g. Using put_attachment. Alternatively, the FileStorage api docs suggest you can use read() to retrieve the data.

这篇关于如何使用flask上传图像并将其存储在couchdb中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆