Home > Enterprise >  Convert image (from url) to File
Convert image (from url) to File

Time:10-07

let url ='https://xxxx/image.jpg';
let blob = new Blob([url]);
let file = new File([blob], "filename", { type: "image/jpg"  });

i am working on an angular project and would love to assign an image to file for upload. However the system cannot load the image after upload. any ideas??

CodePudding user response:

You can do this by using fallowings:

fetch('https://i.imgur.com/fHyEMsl.jpg')
    .then((res) => res.blob())
    .then((myBlob) => {debugger
       const myFile = new File([myBlob], 'image.jpeg', {type: myBlob.type});
    });

  • Related