0

I have the following HTTP Axios getcall that should result the browser to force a download but I get the a strange result instead.

AXIOS Call

    axios.get('http://localhost:63464/api/Consumer/ExcelDownload')
    .then(res => {
        return res.data;
    })
    .then(res =>
    {
        console.log(res);
    })
    .catch(err =>
    {
        console.log(err)
    })

Which is returning the following result from the line in console.log(res);

Result of console.log(res.data) image Here

I was doing the following in the past to get this to work. location.href = 'http://localhost:63464/api/Consumer/ExcelDownload'; which would return my File result. however this route is now protected using a JWT which I have set in axios global headers, so this is no longer working for me.

Would someone be able to help me with this issue? perhaps even being able to create some kind of URL from a blob that I can make the same call to.

UncleFifi
  • 825
  • 1
  • 6
  • 9
  • are you trying to trigger the browser to dowload the file? – Dacre Denny Nov 09 '18 at 04:02
  • @DacreDenny - **Yes** I am. Would you have any suggestions? – UncleFifi Nov 09 '18 at 04:06
  • I faced this problem recently - my solution was to verify the user's credentials via a cookie on server side. Is this possible for you? – Dacre Denny Nov 09 '18 at 04:07
  • Im not sure, I have never done it via a cookie before. I Authenticate the user using a JSON Web Token. – UncleFifi Nov 09 '18 at 04:10
  • Try this: https://stackoverflow.com/questions/41938718/how-to-download-files-using-axios – Dacre Denny Nov 09 '18 at 04:23
  • 1
    Thank you for your help @Dacre, I was able to Download but the file is Corrupted – UncleFifi Nov 09 '18 at 05:28
  • @DacreDenny - Thank you for all your HELP! I was able to figure out from the link you have sent me. I also needed to make an adjustment to my JS HTTP Caller to get it to work. – UncleFifi Nov 09 '18 at 12:41
  • For Anyone reading this... I was able to follow the Link @Dacrea Sent me and also needed to make an slight adjustment via my HTTP Caller. I am using AXIOS, and I needed to do the following to get it to work ...https://thewebtier.com/snippets/download-files-with-axios/ – UncleFifi Nov 09 '18 at 12:43
  • You're welcome glad I could help – Dacre Denny Nov 10 '18 at 05:38

0 Answers0