Angularjs 'FileConstructor is not a constructor'

守給你的承諾、 提交于 2019-12-22 05:59:36

问题


Issue: Error: FileConstructor is not a constructor (evaluating 'new File([blob], "filename.png")')

I saw this question Alternative for File() constructor for safari but there weren't any alternatives worth looking at.

Is there anyway to work around this using Ionic Framework on IOS?

Javascript

a = Base64 image.

 var blob = new Blob([a], {type: 'image/png'});

        console.log(blob);
        $scope.Issue14 = blob;

       var nfile = new File([blob], "filename.png");

        console.log(nfile);
        $scope.Issue15 = nfile;

       var _file = nfile;

        console.log(_file);
        $scope.Issue16 =  _file;

        $scope.Images.push({"img": _file});  

回答1:


I'm facing the same issue with File and Safari. After some research I found a solution that seems to work for me... hope it will be useful for you:

Instead of using new File, i append name and lastModifiedDate fields to the blob.

 blob.name = "filename.png";
 blob.lastModifiedDate = new Date();

It is not a file, but you can use it like it was...



来源:https://stackoverflow.com/questions/38656569/angularjs-fileconstructor-is-not-a-constructor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!