Open xgqfrms opened 6 years ago
https://medium.com/front-end-hacking/fetching-images-with-the-fetch-api-fb8761ed27b2
https://scotch.io/tutorials/how-to-use-the-javascript-fetch-api-to-get-data
http://techstream.org/Bits/Uploading-Image-using-fetch-api
https://stackoverflow.com/questions/164181/how-to-fetch-a-remote-image-to-display-in-a-canvas
https://msdn.microsoft.com/en-us/library/ms527550(v=exchg.10).aspx
https://www.lifewire.com/mime-types-by-content-type-3469108
https://stackoverflow.com/questions/23820011/set-the-header-content-type-image-any-img-format
const fetchImage = (url = ``) => {
return fetch(
url,
// {
// method: "GET",
// mode: "no-cors",
// // mode: "cors",
// // headers: {
// // "Content-Type": "image",
// // // "Content-Type": "image; charset=utf-8",
// // // "Content-Type": "image/png; charset=utf-8",
// // // "Content-Type": "image/jpeg; charset=utf-8",
// // // "Content-Type": "image/gif; charset=utf-8",
// // },
// }
)
.then(res => res.blob())
.then(
(blob) => {
return blob;
}
)
.catch(err => console.log(`fetch image error`, err));
};
fetchImage("https://cdn.xgqfrms.xyz/logo/icon.png")
.then(blob => {
let objectURL = URL.createObjectURL(blob);
let img = document.querySelector(`[data-img="empty-banner-image"]`);
img.src = objectURL;
}).catch(error => console.log(`There has been a problem with your fetch operation: \n`, err.message));
fetch api & image
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#Checking_that_the_fetch_was_successful