我正在开发一个React项目,我第一次使用Cordova插件。我有正确拍照但现在我想使用持久存储将它们本地存储在设备上。我发现相当不错的文档,但由于某种原因无法使此代码工作。如果有人可以提供帮助,我会非常感激!
这是我的功能:
takePicture() {
navigator.camera.getPicture(
imageData => {
this.setState({image: imageData});
let path = 'filesystem:' + imageData;
window.resolveLocalFileSystemURL(
path,
(entry) => {
window.requestFileSystem(
LocalFileSystem.PERSISTENT,
50 * 1024 * 1024,
(fileSys) => {
//The folder is created if doesn't exist
fileSys.root.getDirectory(
'Observation Photos',
{create:true, exclusive: false},
directory => {
let d = new Date(),
n = d.getTime(),
filename = n + '.jpg';
entry.moveTo(directory, filename, (entry) => {
Photos.insert(entry);
}, handleError);
},
handleError
);
},
handleError
);
}, (error) => {
console.log(error);
}
);
}, message => {
console.log(message);
}
);
}

以下是我传递的路径示例:
filesystem:file:///storage/emulated/0/Android/data/com.id1b9kkvri4mj2dnqkf9p/cache/1470171102308.jpg

在检查器中返回:
FileError {code: 5}

答案 0 :(得分:1)
Path的值应为Android/data/com.id1b9kkvri4mj2dnqkf9p/cache/1470171102308.jpg
;
因此需要进行一些小改动:
let path = imageData.replace("file:///storage/emulated/0/","");