【发布时间】:2016-11-25 03:09:00
【问题描述】:
所以我有一个网站(使用 AngularJS)让用户通过标签上传文件
<input type="file" ng-model="image" id="trigger" onchange="angular.element(this).scope().setFile(this)" accept="image/*">
当我在控制器中处理上传时,图像被存储为文件对象。这是我保存文件并设置变量以预览图像的方法
$scope.setFile = function (element) {
$scope.image = element.files[0]; // This is my image as a File
var reader = new FileReader();
//This is for previewing the image
reader.onload = function (event) {
$scope.image_source = event.target.result;
$scope.$apply();
}
reader.readAsDataURL(element.files[0]);
}
现在我正在尝试使用此处找到的 J-I-C 库压缩图像:https://github.com/brunobar79/J-I-C/blob/master/src/JIC.js
但是这个库接受一个图像对象作为它的参数,并将它作为一个压缩的图像对象返回。我似乎找不到将我的 $scope.image File 对象转换为 Image 对象的方法。我该怎么做呢?
我还需要将压缩的图像对象转换回文件,以便将其上传到我的 Azure 存储。
【问题讨论】:
标签: javascript html angularjs image compression