cordovaFile.readAsArrayBuffer ENCODING_ERR

时间:2017-02-22 14:54:12

标签: javascript cordova ionic-framework ngcordova

我试图使用$ cordovaFile.readAsArrayBuffer但我收到以下错误

我在论坛上尝试了一些解决方案,但没有成功

function getFileBlob(url, cb) {
console.log(url);
var path = url.substring(0, url.lastIndexOf('/') + 1);
var filename = url.substring(url.lastIndexOf('/') + 1, url.length);
console.log('path', path);
    console.log('file', filename);
    $cordovaFile.readAsArrayBuffer(path, filename)
            .then(function (success) {
                var blob = new Blob([success], { type: 'image/jpeg' });
                cb(blob);
            }, function (error) {
                onsole.error(error);
                cb(null);
            });
 }

错误: FileError代码:5,消息:" ENCODING_ERR"

Console.logs:

我的网址:/file:///storage/emulated/0/Android/data/com.ionicframework.xx443164/cache/.Pic.jpg

var path:/file:///storage/emulated/0/Android/data/com.ionicframework.xx443164/cache/

var file:.Pic.jpg

我在Android上测试

1 个答案:

答案 0 :(得分:0)

如果您需要将照片作为blob类型

,我认为这可以帮助您
    var photo = url; // your photo                 
 var mainDic = photo.substring(0, photo.lastIndexOf('/') + 1),
     mainArchive = photo.substring(photo.lastIndexOf('/') + 1, photo.length);
 $cordovaFile.readAsArrayBuffer(mainDic, mainArchive).then(function(success) {
     var blob = new Blob([success], {
         type: 'image/jpeg'
     });
     // now blob is your photo as blob type
 }, function(error) {
     console.error(error);
 });