url to blob javascript code example
Example 1: url to blob js
fetch('https://upload.wikimedia.org/wikipedia/commons/7/77/Delete_key1.jpg')
.then(res => res.blob())
.then(blob => {
let objectURL = URL.createObjectURL(blob);
let myImage = new Image();
myImage.src = objectURL;
document.getElementById('myImg').appendChild(myImage)
});
Example 2: create file object from url typescript
fetch('//my-image-url')
.then((e) => {
return e.blob()
})
.then((blob) => {
let b: any = blob
b.lastModifiedDate = new Date()
b.name = ''
return b as File
})