I've looked into it and my syntax looks correct but I can't figure out what is going wrong.
If I don't include the fetch
options
params, everything works fine except that CORS is on, which is what I do not want.
After adding the options
with mode: 'no-cors'
in the request, I am now getting this error with all requested images:
image-cropper-modal.js:73 GET data: net::ERR_INVALID_URL
I have already tried looking at MDN's Using Fetch and https://jakearchibald.com/2015/thats-so-fetch/.
Here is my code:
const options = {
method: 'GET',
mode: 'no-cors'
};
fetch(url, options).then(response => response.blob())
.then(blob => {
let reader = new FileReader();
reader.onload = () => {
const type = blob.type;
const [image, dataUrl] = [new Image(), reader.result];
image.src = dataUrl;
const [width, height] = [image.width, image.height];
const {minWidth, minHeight} = props.opt;
const isWithinBounds = (width >= minWidth) && (height >= minHeight);
callback({
dataUrl,
height,
minHeight,
minWidth,
width
});
}
reader.readAsDataURL(blob)
});