这种在 Django 中发送 couchdb 附件的方法对于一般用途来说是否足够高效?
目前,我正在使用以下代码允许用户下载附加到 couchdb 文档的文件。我正在将 couchdbkit 与 Django 一起使用。
def get_file(request, user_id):
user = User.objects.get(pk = user_id)
application = user.get_profile().application()
attachment_name = request.GET.get('name', None)
assert attachment_name
attachment = application.fetch_attachment(attachment_name, stream=False)
return HttpResponse(attachment, content_type=application._attachments[attachment_name]['content_type'])
这可行,但我担心机器上的内存使用情况。这种方法是否高效,或者大文件会在传递给 HttpResponse 之前转储到内存中?我已经使用了stream=True,但我不确定如何最好地测试它。至少可以说,couchdbkit 上的文档很少。我打算在整个应用程序中使用类似的东西,并希望第一次就能正确使用该方法。 :)
Currently I'm using the below code to allow a user to download a file that's attached to a couchdb document. I'm using couchdbkit with Django.
def get_file(request, user_id):
user = User.objects.get(pk = user_id)
application = user.get_profile().application()
attachment_name = request.GET.get('name', None)
assert attachment_name
attachment = application.fetch_attachment(attachment_name, stream=False)
return HttpResponse(attachment, content_type=application._attachments[attachment_name]['content_type'])
This works, but I am concerned about memory usage on the machine. Is this method efficient, or will large files dump to memory before being passed to the HttpResponse? I have used stream=True, but I'm not sure best how to test this. The documentation on couchdbkit is sparse to say the least. I intend to use something similar to this throughout the application and want to get the method right the first time. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论