所以我有一个网站(使用AngularJS),允许用户通过标签上传文件
<input type="file" ng-model="image" id="trigger" onchange="angular.element(this).scope().setFile(this)" accept="image/*">
Run Code Online (Sandbox Code Playgroud)
当我在控制器中处理上传时,图像被存储为File对象.这是我保存文件的方法,也设置变量来预览图像
$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]);
}
Run Code Online (Sandbox Code Playgroud)
现在我尝试使用这里找到的JIC库来压缩图像:https://github.com/brunobar79/JIC/blob/master/src/JIC.js
但是此库接受图像对象作为其参数,并将其作为压缩图像对象返回.我似乎无法找到将$ scope.image文件对象转换为Image对象的方法.我该怎么做呢?
我还需要将压缩的图像对象转换回文件,以便将其上传到我的Azure存储.