views:

37

answers:

0

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=True)
    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. :)