0
我有以下代碼,由於某種原因,即使成功調用回調函數,它仍不能正常工作。Cordova文件創建目錄不工作
以下是我所知道的目前工作。
- 相機能夠採取圖像和存儲它的應用程序的文件夾中緩存
- 當要在
resolveonsuccess
函數來創建目錄似乎並不要創建的目錄,我身體檢查應用程序的文件夾,它未創建。 - 一旦它重命名文件並移動它,我沒有得到任何錯誤回調,只有成功。
- 文件移動後,它不再在緩存中,文件是否被移動到隱藏文件夾?
任何幫助將不勝感激。
function capturePhoto() { sessionStorage.removeItem('imagepath'); // Take picture using device camera and retrieve image as base64-encoded string navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, destinationType: Camera.DestinationType.FILE_URI }); }
function onPhotoDataSuccess(imageURI) {
// Uncomment to view the base64 encoded image data
console.log(imageURI);
// Get image handle
//
var imgProfile = document.getElementById('imgProfile');
// Show the captured photo
// The inline CSS rules are used to resize the image
//
imgProfile.src = imageURI;
if (sessionStorage.isprofileimage == 1) {
getLocation();
}
movePic(imageURI);
}
// Called if something bad happens.
//
function onFail(message) {
alert('Failed because: ' + message);
}
function movePic(file) {
console.log("Going to move file");
window.resolveLocalFileSystemURI(file, resolveOnSuccess, resOnError);
}
//Callback function when the file system uri has been resolved
function resolveOnSuccess(entry) {
var d = new Date();
var n = d.getTime();
//new file name
var newFileName = n + ".jpg";
var myFolderApp = "OCRFolder";
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSys) {
//The folder is created if doesn't exist
fileSys.root.getDirectory(myFolderApp,
{create: true, exclusive: false},
function (directory) {
entry.moveTo(directory, newFileName, successMove, resOnError);
},
resOnError);
console.log(fileSys.root);
},
resOnError);
}
//Callback function when the file has been moved successfully - inserting the complete path
function successMove(entry) {
//Store imagepath in session for future use
// like to store it in database
console.log("Move was success " + entry.fullPath);
sessionStorage.setItem('imagepath', entry.fullPath);
}
function resOnError(error) {
alert(error.code);
}