0

In my web app users can see a list of some files on the server and they can they press a button to download one of them. This triggers a fetch api call to the server, which then responds by sending the requested file.

I've gotten it to work up to that point. When I check the response in the Network tab of the browser developer tools, I can see the picture that I sent there under the "Preview" section. I receive it using the fetch command below.

The next thing that I would like to happen is for the file to be automatically saved to the client's local hard drive (e.g. the Downloads folder). How can I do this?

            case 'GET_FILE':
                fetch(window.location.origin + '/api/get-file', {
                        method: "POST",
                        body: JSON.stringify(action.docData),
                        headers: {

                        },
                    })
                    .then( response => response.json() 
                    )
                    .then( file => {
                        console.log('API: got docTypes', docTypes)
                        next({
                            type: 'GET_FILE_SUCCEEDED',
                            file
                        })
                    })
                    .catch( error => {
                        console.log('API: docTypes get error!', error)
                        next({
                            type: 'GET_FILE_FAILED'
                        })
                    })
                break
levraininjaneer
  • 1,157
  • 2
  • 18
  • 38

0 Answers0