我使用phonegap / cordova(3.3.0)来访问iOS相机功能。 摄像机的源设置为库,以获取库条目。 如果我从库中选择一个文件,我收到了uri,我想用它来复制文件。
navigator.camera.getPicture(capSucc, capFail,{
sourceType: Camera.PictureSourceType.PHOTOLIBRARY
});
function capSucc(fileURI){
cpyCtrl.copy(fileURI);
}
然后我尝试通过fileURI从localFileSystem获取文件。我收到一个fileEntry,但它停在此文件的复制指令:
window.resolveLocalFileSystemURI(sourceFile, onSuccess, onError);
function onSuccess(fileEntry) {
var root = localStorage.rootPath; //root : /Users/xcode/Library/Application Support/iPhone Simulator/6.0/Applications/2102E3A0-7F22-4C56-A693-EF3CF2A7620F/Documents/
var parentName = root.substring(root.lastIndexOf('/')+1);
var parentEntry = new DirectoryEntry(parentName,root);
fileEntry.copy(parentEntry, "myPic.jpg", succ, fail); //this is where the problem occurs
}
function succ(entry){
alert("copy");
}
function fail(message){
alert("fail");
}
function onError(message){
alert("fileFail");
}
}
文件的目标应该是fileSystem的rootPath。
答案 0 :(得分:1)
我明白了。该功能有拼写错误。我不得不改变
fileEntry.copy(parentEntry, "myPic.jpg", succ, fail); //this is where the problem occurs
到
fileEntry.copyTo...
愚蠢的错误,没有看到它。现在我可以从其他目录中的相机库中复制文件。
答案 1 :(得分:0)
以后可能需要它的任何人参考的完整示例。
var destinationType = navigator.camera.DestinationType;
navigator.camera.getPicture(
function(imageURI) {
window.resolveLocalFileSystemURI(imageURI, function fileEntrySuccess(fileEntry) {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function directoryEntrySuccess(directoryEntry) {
var d = new Date();
var uniqueNewFilename = Date.parse(d) + ".jpg";
fileEntry.moveTo(directoryEntry.root, uniqueNewFilename, function moveFileSuccess(newFileEntry) {
var picPath = newFileEntry.fullPath;
navigator.camera.cleanup(function(){}, function(){});
}, function(){});
}, function(){});
}, function(){});
}, function(message) {
navigator.notification.alert(message, function(){}, 'Picture Not Added');
}, {
quality: 49,
allowEdit: true,
correctOrientation: true,
saveToPhotoAlbum: true,
destinationType: destinationType.FILE_URI
});