将图像文件存储在IndexedDB中 [英] Store an image file in IndexedDB
问题描述
我在尝试在IndexedDB本地存储中存储和映像文件时遇到问题,我抓住文件对象并尝试将其推送到IndexedDB但它似乎抛出并出错:DOM异常:DATA_CLONE_ERR(25)
I'm having issues trying to store and image file in IndexedDB local storage, I grab the file object and try and push that into IndexedDB but it seems to throw and error: DOM Exception: DATA_CLONE_ERR (25)
如何将文件对象(如下所示)转换为我可以存储在indexedDB中并在以后从indexedDB中检索的文件?
How can I convert the file object, which looks like this (below) to something I can store in indexedDB and retrieve from indexedDB at a later date?
attribute: 32
contentType: "image/png"
displayName: "image1"
displayType: "PNG File"
fileType: ".png"
name: "image1.png"
path: "C:\pictures\image1.png"
推荐答案
我相信你的对象可能会发生一些事情,使它看起来与对象文字不同由您在上面列出的键/值对创建。
我建议 console.log
在对象通过 JSON.stringify
后确保它匹配与你的意图一对一。
I believe there might be something going on with your object that makes it look different than the object literal that would be created by the key/value pair you list above.
I suggest console.log
ging the object after it passed through JSON.stringify
to make sure it matches one to one with your intentions.
IndexedDB使用HTML5将对象复制到对象存储中结构化克隆算法。根据规范,无法克隆错误和函数对象并抛出 DATA_CLONE_ERR
,所以请将其作为可能的解释。
IndexedDB copies objects into the object store using the HTML5 structured clone algorithm. According to the spec, Error and Function objects cannot be cloned and throw a DATA_CLONE_ERR
, so look to that as a possible explanation.
这篇关于将图像文件存储在IndexedDB中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!