react js download file
fetch('https://cors-anywhere.herokuapp.com/' + fileURL, {
method: 'GET',
headers: {
'Content-Type': 'application/pdf',
},
})
.then((response) => response.blob())
.then((blob) => {
// Create blob link to download
const url = window.URL.createObjectURL(
new Blob([blob]),
);
const link = document.createElement('a');
link.href = url;
link.setAttribute(
'download',
`FileName.pdf`,
);
// Append to html link element page
document.body.appendChild(link);
// Start download
link.click();
// Clean up and remove the link
link.parentNode.removeChild(link);
});
npm install --save react-download-link
Also in JavaScript:
- is knex built into node js
- angular bootstrap
- get last item in array
- how to use the replace method in javascript
- react Refused to execute inline script because it violates the following Content Security Policy directive
- ng has unexpectedly closed (exit code 127).
- w3schools json
- for each array javascript
- .shift js
- w3schools angular
- node js event emitter
- encrypt script code
- how to go back one directory in git bash
- jquery remove multiple class
- how to use dotenv in javascript
- node express dynamic route and error handler
- jquery get version in console
- how to redirect to another page in javascript on submit type
- js regex password
- Javascript change element class
- convert timestamp to date js
- axios post with header
- js class private
- foreach key value javascript