0

I've to just hit this api and file will be downloaded for the client. Somehow this doesn't work

let res=await axios.get(urlDownload,{params},{responseType: 'blob'}) 

or

let res=await axios.get(urlDownload,{params})

Edit:

  • api doesn't get hit with this, however on running the generated url in browser, file gets dowloaded (with following message)

enter image description here

-able to veiw the response in the network tabs enter image description here

devb
  • 317
  • 3
  • 12
  • 1
    "This doesn't work" is not informative or helpful. Try giving us more information e.g. error you're getting, what are you trying to acheive what kind of params object you're passing. how the server end is implemented. Everything that could help us understand where the problem is located. – Orel Eraki Nov 28 '20 at 21:20
  • @OrelEraki please check – devb Nov 28 '20 at 21:28
  • 127.0.0.1 is your own machine. You should be able to connect to it unless your firewall is blocking you. What's the exact URL you're trying to download? – Slbox Nov 28 '20 at 21:29
  • @Slbox in networks tab i can see the url, on clicking it the file is getting dowloaded – devb Nov 28 '20 at 21:32
  • @devb Did the server located on your personal computer ? And are you sure you paste the url in browser and navigating to it and it download the file + shows the error afterwards ? Also please paste the full generated url – Orel Eraki Nov 28 '20 at 21:33
  • Yes the server in local , pasting the url in edits – devb Nov 28 '20 at 21:35
  • 1
    @devb have you tried https://stackoverflow.com/a/53230807/303254 ? – Orel Eraki Nov 28 '20 at 21:38

1 Answers1

0

Either place a codesandbox where you have your full code or
check your set up against the code below:

function download(values) {
    ...
    const method = 'GET';
    const url = 'http://my.api/download';
    ...
    axios
      .request({
        url,
        method,
        responseType: 'blob', //<< important
      })
      .then(({ data }) => {
// do something with the data
      });
  };

Not clear what you have in params

Ivan Satsiuk
  • 333
  • 2
  • 9