创建目录时遇到问题,这是我的代码:
var d = new Date();
var n = d.getTime();
var newFileName = n + ".jpg";
var myFolderApp = "myFolder";
var newFile=myFolderApp+"/"+newFileName;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) {
alert('root is :'+fileSys.root.name)
fileSys.root.getDirectory("myFolder",{create:true, exclusive: false},
function(directory)
{
alert('direcrory name :'+directory.name)
fileSystem.copyTo(directory, newFileName,function(fileSystem)
{
alert('file sved!')
}, resOnError);
},
resOnError);
},
resOnError);
function resOnError(error) {
alert('Error at resOnError :'+error.code+' ,message :'+eror.message);
}
还添加了读写权限。
3. 目录未创建且代码执行且没有错误。
由于
HERE的代码 var pictureSource; //图片来源 var destinationType; //设置返回值的格式
(function(){
document.addEventListener("deviceready", onDeviceReady, false);
})();
function onDeviceReady()
{
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
function save()
{
alert(imageForCategory)
window.resolveLocalFileSystemURL(imageForCategory,resolveOnSuccess,resOnError);
}
function onFail(message)
{
alert('Failed because: ' + message);
}
function getPhoto(source)
{
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 100,destinationType: destinationType.FILE_URI,sourceType: source });
}
var imageForCategory="";
function onPhotoURISuccess(imageURI)
{
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
largeImage.src = imageURI;
imageForCategory=largeImage.src;
}
function resOnError(error) {
alert('Error at resOnError :'+error.code+' ,message :'+error.message);
}
function resolveOnSuccess(fileSystem)
{
alert('on resolve success called');
var d = new Date();
var n = d.getTime();
var newFileName = n + ".jpg";
var myFolderApp = "myFolder";
var newFile = myFolderApp + "/" + newFileName;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSys) {
alert('root is :' + fileSys.root.name);
fileSys.root.getDirectory("myFolder", {create: true, exclusive: false},
function (directory) {
alert('directory name :' + directory.name);
directory.getFile(newFileName, {create: true}, function (file) {
alert("File created.");
});
}, resOnError);
}, resOnError);
}
答案 0 :(得分:0)
我不知道你到底想做什么。它接缝要复制文件,但是你没有说明来源。
如果要创建文件,请使用以下代码:
var d = new Date();
var n = d.getTime();
var newFileName = n + ".jpg";
var myFolderApp = "myFolder";
var newFile = myFolderApp + "/" + newFileName;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSys) {
alert('root is :' + fileSys.root.name);
fileSys.root.getDirectory("myFolder", {create: true, exclusive: false},
function (directory) {
alert('directory name :' + directory.name);
directory.getFile(newFileName, {create: true}, function (file) {
alert("File created.");
});
}, resOnError);
}, resOnError);
function resOnError(error) {
alert('Error at resOnError :' + error.code + ' ,message :' + eror.message);
}