Angularjs 'FileConstructor is not a constructo

2019-04-29 15:14发布

问题:

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...