带有图像字段的烧瓶MongoEngine分页文档 [英] Flask MongoEngine Paginated Documents with Image Field

查看:400
本文介绍了带有图像字段的烧瓶MongoEngine分页文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有看到这个确切的问题张贴,所以随时指出,如果它存在。我也是mongo的新手,所以我的言论可能很奇怪。

我有一个文档集合,最终会变得非常大。我已经建立了这样的文件有一个ImageField。我想返回完整的文档以及作为一个文件填充的ImageField的缩略图,以便我可以在我的html5 / javascript前端显示它。



在SQL中,这将是

见这里:

  from flask_mongoengine import MongoEngine 
import datetime
$ b db = MongoEngine()
$ b class img_audit(db.Document):
request_image = db.ImageField( size =(1920,1080,True),thumbnail_size =(100,100,True))
processed_date = db.DateTimeField(default = datetime.datetime.utcnow)
state = db.StringField()
city = db.StringField()

查询:

  form = request.form 
dpage = form ['page']
perpage = form ['perpage']
pag_audits = img_audit.objects.paginate(page = int(dpage),per_page = int(perpage))
pag_res = []
用于pag_audits.items中的项目:
pag_res.append(item.to_j son())
return jsonify({'audits':pag_res})

查询只是返回ImageField的_oid,就好像它是一个嵌套的文档。我怎样才能得到缩略图,并返回所有这一切在一个旋转?

在用户界面上,当用户点击缩略图,我会做一个获取请求为高清晰图像。

感谢任何提示!
$ b

------- UPDATE 1 --------------



试过以下内容:

pre > pag_audits = img_audit.objects.only('processed_date','state','city','request_image.thumbnail')。

获取以下错误:
mongoengine.errors.LookUpError:无法解析子字段或运算符缩略图在字段request_image

解决方案

我最终只使用Mongo作为键/值和Azure Blob存储来存储文件。由于各种原因,从成本到内容交付和扩展能力,这最终成为了一个更好的解决方案。


Not seeing this exact question posted, so feel free to point to it if it exists. I'm also new to mongo, so my verbiage is likely weird.

I have a document collection which will eventually grow very large. I have set up so that the document has an ImageField. I want to return the full document along with the ImageField's thumbnail populated as a file such that I can display it in my html5/javascript front end.

In SQL this would be accomplished through a column selector and a join.

See here:

from flask_mongoengine import MongoEngine
import datetime

db = MongoEngine()

class img_audit(db.Document):
    request_image = db.ImageField(size=(1920, 1080, True), thumbnail_size=(100, 100, True))
    processed_date = db.DateTimeField(default=datetime.datetime.utcnow)
    state = db.StringField()
    city = db.StringField()

Query:

form = request.form
dpage = form['page']
perpage = form['perpage']
pag_audits = img_audit.objects.paginate(page=int(dpage), per_page=int(perpage))
pag_res = []
for item in pag_audits.items:
    pag_res.append(item.to_json())
return jsonify({'audits' : pag_res})

Currently the query simply returns the _oid of the ImageField as if it were a nested document. How can I get just the thumbnail and return all of this in one whirl?

On the user interface, when the user clicks on the thumbnail, I will do a get request for the high definition image.

THANKS for any tips!

-------UPDATE 1--------------

Tried the following:

pag_audits = img_audit.objects.only('processed_date', 'state', 'city', 'request_image.thumbnail').paginate(page=int(dpage), per_page=int(perpage))

Getting the following error: mongoengine.errors.LookUpError: Cannot resolve subfield or operator thumbnail on the field request_image

解决方案

I ended up just using Mongo as a key/value and Azure Blob storage to store the files. This ended up being a better solution for a variety of reasons from cost to content delivery and scale-ability.

这篇关于带有图像字段的烧瓶MongoEngine分页文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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