错误:无法在“窗口”上执行“ atob”:要解码的字符串未正确编码
这是我的Javascript代码
function upload(){var byteCharacters = atob($scope.image1.compressed.dataURL.replace(/^data:image\(png|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
});
这是我的HTML
<div class="form-group text-16px" style="margin-top: 20px !important;"> <label>Choose Material Photo : </label>
<div>
<input id="materialImage" type="file" accept="image/*" image="image1" resize-max-height="800" resize-max-width="800" resize-quality="0.7" resize-type="image/jpg" file-model="file" name="materialImage" onChange="checkFile()" ng-image-compress/>
<div id="choose-image-compresser">
<div image="image1" result-image="myCompressedImage"></div>
</div>
<img ng-src="{{image1.compressed.dataURL}}" />
<span id="image-size-error" style="color:red;" hidden=""><small>Image size is too large</small></span>
</div>
</div>
错误:无法在“窗口”上执行“ atob”:要解码的字符串未正确编码
回答:
我有我的问题。这对于其他用户使用javascript(AnguarJs)保存图像和压缩图像应该会有所帮助。
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
});
以上是 错误:无法在“窗口”上执行“ atob”:要解码的字符串未正确编码 的全部内容, 来源链接: utcz.com/qa/413972.html