Error:Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded

前端 未结 2 1440
我在风中等你
我在风中等你 2021-01-01 21:42

This is my Javascript code

function upload(){
var byteCharacters = atob($scope.image1.compressed.dataURL.replace(/^data:image\\(png|jpg);base64,/,         


        
相关标签:
2条回答
  • 2021-01-01 22:14

    After checking out your code it seems like you have characters which are not probably supported. Check screenshot If that doesn't work make sure the name of the file you are trying to upload is encoded to what your database or settings support.

    Here is the code without those characters:

    var byteCharacters = atob($scope.image1.compressed.dataURL.replace(/^data:image\/(png|jpg);base64,/,'')); var byteNumbers = new Array(byteCharacters.length);
    
    0 讨论(0)
  • 2021-01-01 22:37

    I got my problem. It should be helpful for another user for save the image and compress the image using javascript(AnguarJs).

    I am flowing this link to compress the image Github

    https://github.com/oukan/angular-image-compress

    var imageData = $scope.image1.compressed.dataURL.toString();
    var byteCharacters = atob(imageData.replace(/^data:image\/(png|jpeg|jpg);base64,/, ''));
    var byteNumbers = new Array(byteCharacters.length);
    for (var i = 0; i < byteCharacters.length; i++) {
      byteNumbers[i] = byteCharacters.charCodeAt(i);
    }
    
    var byteArray = new Uint8Array(byteNumbers);
    var blob = new Blob([ byteArray ], {
       type : undefined
    });
    
    0 讨论(0)
提交回复
热议问题