I'm trying to download a pdf file from a flask endpoint through react and fetch.
Endpoint:
@main.route('/uploads', methods=['GET'])
def download_file():
return send_from_directory(UPLOAD_FOLDER, 'newfile.pdf', as_attachment=True)
Function used to make request:
async () => {
const response = await fetch('http://127.0.0.1:5000/uploads', {
method: 'GET',
});
console.log(response);
}
It seems like that the response was successful but the file does not get downloaded. But if I go to the flask endpoint(http://127.0.0.1:5000/uploads) on my browser, the file does download.
This is the response I am getting:
type: "basic"
url: "http://127.0.0.1:5000/uploads"
redirected: false
status: 200
ok: true
statusText: "OK"
headers: Headers {}
body: (...)
bodyUsed: false
What am I doing wrong? Any help would be much appreciated!