P粉0051346852023-08-23 12:08:41
Convert it to base64 and save it.
function gotPhoto(element) { var file = element.files[0]; var reader = new FileReader() reader.onload = function(base64) { localStorage["file"] = base64; } reader.readAsDataURL(file); } // 保存到本地存储 function getPhoto() { var base64 = localStorage["file"]; var base64Parts = base64.split(","); var fileFormat = base64Parts[0].split(";")[1]; var fileContent = base64Parts[1]; var file = new File([fileContent], "文件名", {type: fileFormat}); return file; } // 获取文件对象
P粉8113491122023-08-23 11:45:18
You cannot serialize File API objects.
Although this does not solve the specific problem, but... While I haven't used this, if you look at this post there seems to be some way (although not yet supported by most browsers) to store offline image data into some file so that it can be used when the user Restore them while online (without using localStorage)