I am converting a blob image to a File object, uploading to local storage and retrieving it, but when i retrieve it the file object isn't in the format i expect.
I am converting a blob image to a file object like so:
async function convertBlobUrlToFile(image, filename, fileType) {
const response = await fetch(image);
const blobData = await response.blob();
const uploadFileImage = new File([blobData], filename, { type: fileType });
return uploadFileImage;
}
and uploading it to local storage like so:
convertBlobUrlToFile(croppedImage, imageFileName, fileType).then((blobObject) => {
localStorage.setItem('croppedImage', blobObject);
}).catch((error) => {
console.error(error)
})
which looks like a normal file object, an example is
File {name: 'ProfilePic.jpg', lastModified: 1679604282406, lastModifiedDate: Thu Mar 23
2023 20:44:42 GMT+0000 (Greenwich Mean Time), webkitRelativePath: '', size: 600329, …}
however when i retrieve it, it just says
[object File]
I try to use JSON.parse
to see if anything changes but i don't have much luck.
Can someone help me in trying to store the File object into local storage correctly please so when i do localStorage.getItem()
it is an actual File object like the example above.
Thank you for anyone helping :)