Open
Description
fake-indexeddb
seems to support the storage of blobs (#56); however, if one attempts to store a File
, then the file, when retrieved, will be converted into a Blob
, and part of its information, such as file name, will be lost.
Example:
require('fake-indexeddb/auto');
const STORE_NAME = 'TEST';
const testId = 'test-id';
const file = new File([
'hello world!'
], 'file.txt');
console.log('File prototype:', Object.getPrototypeOf(file)); // Blob [File] { name: [Getter], lastModified: [Getter] }
const request = indexedDB.open("test", 3);
request.onupgradeneeded = function () {
const db = request.result;
const store = db.createObjectStore(STORE_NAME);
store.put({
title: "My test record",
file
}, testId);
}
request.onsuccess = function (event) {
const db = event.target.result;
const tx = db.transaction(STORE_NAME);
tx.objectStore(STORE_NAME).get(testId).addEventListener("success", function (event) {
const result = event.target.result;
console.log("RETRIEVED:", result); // prints { title: 'My test record', file: Blob { size: 12, type: '' } }
console.log('File prototype', Object.getPrototypeOf(result.file)); // the prototype of the file is now Object [Blob]
});
tx.oncomplete = function () {
console.log("All done!");
};
};
Metadata
Metadata
Assignees
Labels
No labels