0

I am building a webapp in AngularJS frontend with a Python Flask backend and a MongoDB/GridFS database.

I want to make the client download a file in the browser, the same way on direct download website for instance. The file is saved in gridFS

Here is the code :

Backend routing:

@router.route('/getOrgaUploadedDocument/<doc_id>/<doc_name>', methods=['GET'])
@requires_auth
def getOrgaUploadedDocument(user, doc_id, doc_name):
    ret = base_orga.getOrgaUploadedDocument(user, doc_id)
    return ret

Backend Handling (the base_orga object):

def getOrgaUploadedDocument(user, doc_id):
    gfile = db_filesystem.get(objectid.ObjectId(doc_id))
    return Response(gfile, mimetype=gfile.doc_type, direct_passthrough=True)

Frontend :

ctrl.downloadDoc = function (doc_id, doc_name) {
$http.get('/getOrgaUploadedDocument/' + doc_id + "/" + doc_name ).then(function(response) {
    console.log(response);
});

}

So i get the raw bytes of my file in the console, obviously.

But I can't find a way to formulate the request to trigger a file download in the browser.

Thanks.

Jidey
  • 359
  • 2
  • 6
  • 20

0 Answers0