Skip to content

Instantly share code, notes, and snippets.

@miteshmap
Last active January 8, 2021 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miteshmap/17d32c00eb91ebd4fbd54af3fdc96a14 to your computer and use it in GitHub Desktop.
Save miteshmap/17d32c00eb91ebd4fbd54af3fdc96a14 to your computer and use it in GitHub Desktop.
Download blob data with axios
import axios from "axios";
import { saveAs } from "file-saver";
axios(`${apiUrlPrefix}/file/5`, {
method: 'GET',
responseType: 'blob',
headers: {
'Authorization': `Bearer ${token}`,
}
}).then(response => {
saveAs(new Blob([response.data], {type: "text/plain;charset=utf-8"}), 'file.txt');
})
.catch(error => {
console.log(error);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment