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.

2
  • take a look at: stackoverflow.com/a/29556434/1326271 Commented Feb 19, 2017 at 15:38
  • I tried to but it still doesn't work ... Commented Feb 20, 2017 at 10:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.