Cordova 3.5.0 FileError.NOT_FOUND_ERR(代码:1)上传文件时出错 > 256MB

Posted

技术标签:

【中文标题】Cordova 3.5.0 FileError.NOT_FOUND_ERR(代码:1)上传文件时出错 > 256MB【英文标题】:Cordova 3.5.0 FileError.NOT_FOUND_ERR (Code:1) Error uploading files > 256MB 【发布时间】:2014-07-17 14:33:32 【问题描述】:
Cordova 3.5.0
FileTransfer 0.4.4
iPad 2 version 7.1.2
error: FileError.NOT_FOUND_ERR (Code:1)
Error uploading files ios > 256MB

日志设备:

Jul 15 17:12:34 iPad-Sergej CueVu[119] <Warning>: THREAD WARNING: ['Camera'] took '18.839844' ms. Plugin should use a background thread.
Jul 15 17:13:24 iPad-Sergej CueVu[119] <Warning>: Error opening file file:///private/var/mobile/Applications/D51C7F13-09AE-42D3-A613-83D5005C55F2/tmp/trim.ED614CFF-CBE0-4A8C-82D2-E507F3DA9B0D.MOV: Error Domain=NSCocoaErrorDomain Code=256 "The operation couldnt be completed. (Cocoa error 256.)" UserInfo=0x1a978b60 NSFilePath=/private/var/mobile/Applications/D51C7F13-09AE-42D3-A613-83D5005C55F2/tmp/trim.ED614CFF-CBE0-4A8C-82D2-E507F3DA9B0D.MOV, NSUnderlyingError=0x14dfa590 "The operation couldnt be completed. Cannot allocate memory"
Jul 15 17:13:24 iPad-Sergej CueVu[119] <Warning>: FileTransferError 
code = 1;
source = "file:///private/var/mobile/Applications/D51C7F13-09AE-42D3-A613-83D5005C55F2/tmp/trim.ED614CFF-CBE0-4A8C-82D2-E507F3DA9B0D.MOV";
target = "https://myserver.com/my/mobile/uploadFile/t:153c52738326e2153c5273832ac7153c5273832eb0153c5273833298";

Jul 15 17:13:24 iPad-Sergej CueVu[119] <Warning>: THREAD WARNING: ['FileTransfer'] took '39.189209' ms. Plugin should use a background thread.
Jul 15 17:13:24 iPad-Sergej CueVu[119] <Warning>: THREAD WARNING: ['Notification'] took '67.596924' ms. Plugin should use a background thread.

代码:

function uploadVideo(meeting_id) 
var chargeBar = '';

 navigator.camera.getPicture(        
     successGetFileFromCamera,
     failGetFileFromCamera,
      
         quality: 50,
         destinationType: navigator.camera.DestinationType.FILE_URI,
         sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
         mediaType: navigator.camera.MediaType.VIDEO
     
 );

function successGetFileFromCamera(fileURI) 
    uploadFileToServ(fileURI);
 

function failGetFileFromCamera(message) 
    showError(message);         


function uploadFileToServ(fileURI) 
    alert(fileURI);
    var options = new FileUploadOptions();
    options.fileKey = "my_video";
    options.fileName = fileURI.substr(fileURI.lastIndexOf('/')+1);
    options.mimeType="video/mp4";
    var params = ;
    params.meeting_id = meeting_id;
    options.params = params;
    options.chunkedMode = true;

    var ft = new FileTransfer();        
    ft.onprogress = function(progressEvent) 
        if(progressEvent.lengthComputable) 
          updateProgress(Number(((progressEvent.loaded / progressEvent.total) * 100).toFixed(1)));                        
        
    ;

    showProgress();

    ft.upload(fileURI, encodeURI(window.cuevuHost + "/cuevu/mobile/uploadFile/t:" + window.cuevuToken), successUploadFileToServ, failUploadFileToServ, options);


function showProgress()        
    $("#progress_window").popup('open');
    $("#progress_window_content").html("<div id='chargeBar'></div>");
    chargeBar = new Progress.bar( id: "progress1", autoRemove: false, backgroundSpeed: 5, type: "charge", showPercentage: true);
    chargeBar.renderTo(document.getElementById('chargeBar'));
    $('.ui-popup-screen').off();
   

function updateProgress(value) 
    chargeBar.update(value);
 

function closeProgress() 
    $("#progress_window").popup('close');


function successUploadFileToServ(r)        
    closeProgress();        
    data = $.parseJSON(r.response);
    if(data.result == true) 
        navigator.notification.alert('Video file has been successfully loaded', null, 'Upload file', null);
     else 
        dataHaveError(data);
    


function failUploadFileToServ(error) 
    closeProgress();
    showError("File Transfer: Code = " + error.code);       



请帮忙,是什么错误原因看不懂...

【问题讨论】:

【参考方案1】:

请将您对 uploadFileToServ 函数的实现更改为以下

function uploadFileToServ(fileURI) 
window.resolveLocalFileSystemURI(fileURI, function (fileEntry) 
fileEntry.file(function (fileObj) 
var fileName = fileObj.fullPath;

alert(fileName);
var options = new FileUploadOptions();
options.fileKey = "my_video";
options.fileName = fileURI.substr(fileURI.lastIndexOf('/')+1);
options.mimeType="video/mp4";
var params = ;
params.meeting_id = meeting_id;
options.params = params;
options.chunkedMode = true;

var ft = new FileTransfer();        
ft.onprogress = function(progressEvent) 
    if(progressEvent.lengthComputable) 
      updateProgress(Number(((progressEvent.loaded / progressEvent.total) * 100).toFixed(1)));                        
    
;

showProgress();

ft.upload(fileName encodeURI(window.cuevuHost + "/cuevu/mobile/uploadFile/t:" +    window.cuevuToken),    successUploadFileToServ, failUploadFileToServ, options);


【讨论】:

谢谢!仅使用localURL 代替fullPath。只是现在另一个问题***.com/questions/24867759/…

以上是关于Cordova 3.5.0 FileError.NOT_FOUND_ERR(代码:1)上传文件时出错 > 256MB的主要内容,如果未能解决你的问题,请参考以下文章

Cordova 3.5.0 中的 iPhone 屏幕方向没有改变

Cordova 3.5.0 FileError.NOT_FOUND_ERR(代码:1)上传文件时出错 > 256MB

Phonegap (NOT Cordova) 3.5 示例应用程序未启动 deviceready

iOS 8 和 Cordova:应用程序在首次启动时立即请求推送通知权限

Phonegap构建相机不工作

Cordova与现有框架的结合,Cordova插件使用教程,Cordova自定义插件,框架集成Cordova,将Cordova集成到现有框架中