
GAE文档讨论了使用BlobProperty在数据存储区中存储图像,这应该是这样的: –
class MyPics(db.Model): name=db.Stringproperty() pic=db.Blobproperty()
现在,图像应该存储在数据存储区中:
def storeimage(): pics=MyPics() pics.name=request.form['name'] uploadedpic=request.files['file'] #where file is the fIEldname in the form of the file uploaded pics.pic=db.Blob(uploadedpic) pics.put() redirect ... etc etc
但我无法做到这一点.因为我得到db.Blob接受一个字符串,但给定一个filestorage对象…有人可以帮我这个.此外,如果有人可以提示我如何在上传后将图像流回来.
解决方法 好的,这就是我最终解决它的方法: –@userreg.route('/mypics',methods=['GET','POST'])def mypics(): if request.method=='POST': mydata=MyPics() mydata.name=request.form['myname'] file=request.files['file'] filedata=file.read() if file: mydata.pic=db.Blob(filedata) mydata.put() return redirect(url_for('home')) return render_template('mypicform.HTML') 上面将文件存储为数据存储区中的blob,然后可以通过以下函数检索:
@userreg.route('/pic/<name>')def getpic(name): qu=db.query(MyPics).filter('name =',name).get() if qu.pic is None: return "hello" else: mimetype = 'image/png' return current_app.response_class(qu.pic,mimetype=mimetype,direct_passthrough=False) 总结 以上是内存溢出为你收集整理的使用Flask(Python)在Google数据存储中存储图像全部内容,希望文章能够帮你解决使用Flask(Python)在Google数据存储中存储图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)