Download file from fetch()

PHOTO EMBED

Fri May 03 2024 18:15:39 GMT+0000 (Coordinated Universal Time)

Saved by @porobertdev #javascript #promise

const url ='http://sample.example.file.doc'
const authHeader ="Bearer 6Q************" 

const options = {
  headers: {
    Authorization: authHeader
  }
};
 fetch(url, options)
  .then( res => res.blob() )
  .then( blob => {
    var file = window.URL.createObjectURL(blob);
    window.location.assign(file);
  });
content_copyCOPY

https://stackoverflow.com/questions/32545632/how-can-i-download-a-file-using-window-fetch