2015-09-11 21 views
6

Bằng cách nào đó tôi tiếp tục nhận được "mã lỗi 5" khi cố gắng đặt quyền sau. Điều tôi muốn làm là sao chép tệp hiện có từ nội dung trong Android sang một điểm có thể truy cập trên thiết bị Android để có thể chia sẻ nó trên các ứng dụng khác (như thư).Cordova: Không thể sao chép tệp trên Android bằng Cordova

Dưới đây là ví dụ mã của tôi:

window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem; 
    var storagefolder = cordova.file.dataDirectory; 
    var storagefolderpointer; 
    console.log("storage folder: " + storagefolder); 

    // Check for support. 
    if (window.requestFileSystem) { 
     console.log("filesystem beschikbaar"); 
     var getFSfail = function() { 
      console.log('Could not open filesystem'); 
     }; 
     var getFSsuccess = function(fs) { 

      var getDIRsuccess = function (dir) { 
        console.debug('Got dirhandle'); 
        cachedir = dir; 
        fileurl = fs.root.fullPath + '/' + storagefolder; 
        storagefolderpointer = dir; 
      }; 
      var getDIRfail = function() { 
       console.log('Could not open directory'); 
      }; 

      console.debug('Got fshandle'); 
      FS = fs; 
      FS.root.getDirectory(storagefolder, {create:true,exclusive:false}, getDIRsuccess, getDIRfail); 
     }; 
     window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, getFSsuccess, getFSfail); 

     setTimeout(function() { 

      console.log("directory beschikbaar"); 
      var suc = function(entry){ 
       var goe = function(){ 
        console.log("copy success"); 
       }; 
       var fou = function(){ 
        console.log("copy NOT NOT success"); 
       }; 
       entry.copyTo(storagefolder, "vcard.vcf", goe, fou); 
      }; 
      var fai = function(e){ 
       console.log("fail getFile: " + e.code); 
      }; 
      window.resolveLocalFileSystemURL(storagefolderpointer + "www/visitekaart/vcard.vcf", suc, fai); 

     }, 1000); 

    } else { 
     console.log("filesystem NOT NOT NOT available"); 
    } 
+2

Có liên quan đến [vấn đề này] (https://github.com/driftyco/ng-cordova/issues/506)? Xem nhận xét thứ 10 – lifeisfoo

+0

Bạn đã thử sử dụng trình chỉnh sửa dữ liệu chưa? https://github.com/MaginSoft/MFileChooser –

+1

Lỗi này là 'ENCODING_ERR' như là các tài liệu https://github.com/apache/cordova-plugin-file, vui lòng nêu rõ trong câu hỏi có thể có liên quan. –

Trả lời

3

có bạn sử dụng cordovaFile Plugin thay vào đó, bạn có thể sử dụng blob để đọc nội dung của tập tin của bạn hơn viết một cái mới trên sdcard android sử dụng cordovaFile Plugin

$cordovaFile.writeFile('appdata/file.txt', blob, 0).then(function(fileEntry) { 
    //success 
}, function(err) { 
    //err 
} 
Các vấn đề liên quan