2016-12-07 381 views
0

最近我发现我无法从我的应用(iOS)上传图片和视频。经过调查,函数window.resolveLocalFileSystemURL总是失败并返回{“code”:5}。不过,它直到最近才开始工作,我没有遇到Android的这个问题。我的代码如下:window.resolveLocalFileSystemURL返回代码5

$('#take_picture').click(function(){ 
    navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 60, destinationType: Camera.DestinationType.FILE_URI, correctOrientation: true, targetHeight: 621, targetWidth: 621 }); 
}); 
$('#take_video').click(function(){ 
    var options = { limit: 1, quality: 0, duration: 10 }; 
    navigator.device.capture.captureVideo(onCaptureSuccess, onCaptureFail, options); 
}); 

function onCaptureSuccess(mediaFiles) { 
    var i, len; 
    for (i = 0, len = mediaFiles.length; i < len; i += 1) { movePic(mediaFiles[i].fullPath); } 
} 

function onPhotoDataSuccess(imageURI) { 
    if (device.platform == 'iOS') { file = file.replace('/private/', 'file:///'); } 
    movePic(imageURI); 
} 
function movePic(file){ 
    window.resolveLocalFileSystemURL(file, resolveOnSuccess, function(data){ alert(JSON.stringify(data)); }); 
} 

变量文件是这样的文件:///var/mobile/Containers/Data/Application/UID/tmp/cdv_photo_021.jpg

你知不知道我应该怎么做它使它工作?

+0

您是否试图写入您的应用程序目录?如果是这样,我不知道你可以这样做:https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/#ios-file-system-layout –

+0

感谢您的评论。实际上,在你提到/ tmp /文件夹是可写的页面之前,它运行良好。 – Pierre

+0

我收到编码区域的时间通常是在尝试写入我无法写入的文件夹时。我会建议试图在其他地方写文件来测试这个理论 –

回答

0

最后,我完全卸载/重新安装了Phonegap,更新了Cordova-ios,现在解决了这个问题,即使不修改任何代码行。