Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140788

Downloading pdf file from flask through react and fetch

$
0
0

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!


Viewing all articles
Browse latest Browse all 140788

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>