Get 2024 Templates Mega Bundle!14 Bootstrap, Vue & React Templates + 3 Vector Sets
Get for 99$

how to download a file from API in vue


i tried to download some file generated in my BE from API which work normal on other project but when i tried to use it in metronic excel can not read the file

my module:

@Action
[SalePlan.TEST]() {
return new Promise<void>((resolve, reject) => {
ApiService.post(`/bhtt/salePlan/test`, {}, { responseType: "blob" }).then(({ data }) => {
resolve(data);
})
.catch(({ response }) => {
reject(response);
});
});
}


i used this to download the file:

this.store
.dispatch(SalePlan.TEST)
.then((res) => {
saveAs(
new Blob([res]),
"Report.xlsx"
);
});


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (4)


Hi,

Thank you for reaching out to us.

Could you please specify which Metronic version you are using?

Do you have any errors in your browser's console?

Regards,
Lauris Stepanovs,
Keenthemes Support Team



im using Metronic 8 and there are no errors in console regarding fetching data from the API or downloading it using file-saver.
When i replace "ApiService" with "axios" it worked like normal

@Action
[SalePlan.TEST]() {
return new Promise<void>((resolve, reject) => {
axios.post(`/bhtt/salePlan/test`,{}, { responseType: "blob" }).then(({ data }) =>{
resolve(data);
})
.catch(({ response }) => {
reject(response);
});
});
}



After further inspections i've found that the ApiService.ts file on our project was changed when we were testing and getting used to the template, im sorry for taking your time and thank you for your reply



Hi,

Sorry for the late reply.

I am glad to hear you have already managed to fix it. Please let us know if you have more questions on this topic or anything else.

Regards,
Lauris Stepanovs,
Keenthemes Support Team


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(