Img src path with header params to pass

You can now use fetch() to add your headers and then load the result into an <img>:

const src="https://api.mywebsite.com/profiles/123/avatar";
const options = {
  headers: {
    'Some-Header': '...'
  }
};

fetch(src, options)
.then(res => res.blob())
.then(blob => {
  imgElement.src = URL.createObjectURL(blob);
});

Leave a Comment