很容易将文件存储在 indexedDB 中。indexedDB 对于大型数据库等很有用,但即使您只是放入一个文件,它仍然可以工作。我知道@Gaurav 说了一些关于 indexedDB 的事情,但我会给你一个如何存储它的例子:
var indexedDB=window.indexedDB||window.webkitIndexedDB||window.mozIndexedDB;
function storeFile(fileObj,callback){
var openReq=indexedDB.open('upload-resume',1);
openReq.onerror=function(e){
console.error(e);
}
openReq.onupgradeneeded=function(e){
var db=openReq.result;
db.createObjectStore('upload-resume-store',{keyPath:'blah'});
}
openReq.onsuccess=function(e){
var db=openReq.result;
var req=db.transaction(['upload-resume-store'],'readwrite').objectStore('upload-resume-store').add({blah:'main',file:fileObj});
req.onerror=function(e){
console.error(e);
}
req.onsuccess=function(e){callback();}
}
}
function getFile(callback){
var openReq=indexedDB.open('upload-resume',1);
openReq.onerror=function(e){
console.error(e);
}
openReq.onupgradeneeded=function(e){
//this should have already been called before...so if this is here that means that the file was never stored
openReq.onsuccess=null;
callback(false);
}
openReq.onsuccess=function(e){
var req=db.transaction(['upload-resume-store'],'readonly').objectStore('upload-resume-store').get('blah');
req.onerror=function(e){
console.error(e);
}
req.onsuccess=function(e){
callback(req.result);
}
}
}
我以前遇到过 indexedDB 的问题,如果它不能正常工作,请告诉我。