I am using ng-file-upload directive to upload files to nodejs in my application. Now, I am trying to compress the image before uploading. To do that I have tried using compress method of Java Image Compress(JIC) library. It is successfully compressing an image. Now, the problem is, I have to send a file object to my server(nodejs) but compress method returns an image with src attribute. Is there any way to get file object with url? or any other alternative way of achieving compress at angularjs and upload to nodejs? Any help appreciated.
我正在使用ng-file-upload指令将文件上传到我的应用程序中的nodejs。现在,我正在尝试在上传之前压缩图像。为此,我尝试使用Java Image Compress(JIC)库的压缩方法。它成功压缩图像。现在,问题是,我必须将文件对象发送到我的服务器(nodejs),但是compress方法返回一个带有src属性的图像。有没有办法用url获取文件对象?或者在angularjs上实现压缩并上传到nodejs的任何其他替代方法?任何帮助赞赏。
2 个解决方案
#1
4
I think ng-image-compress will solve your issue. To use this,
我认为ng-image-compress将解决您的问题。要用它,
- Download ng-image-compress
- 下载ng-image-compress
- Bower - bower install angular-image-compress.
- 凉亭 - 凉亭安装角度图像压缩。
- Include angular.js and angular-image-compress.js in your application and add ngImageCompress as dependency to your main module.
- 在应用程序中包含angular.js和angular-image-compress.js,并将ngImageCompress作为依赖项添加到主模块中。
angular.module('myApp', ['ngImageCompress']);
angular.module('myApp',['ngImageCompress']);
Then you can include "resize-max-height="800" resize-max-width="800" resize-quality="0.7" resize-type="image/jpg" ng-image-compress " in your File Type input to compress your image.
然后你可以在文件类型输入中包含“resize-max-height =”800“resize-max-width =”800“resize-quality =”0.7“resize-type =”image / jpg“ng-image-compress”压缩你的形象。
You can find more details from https://github.com/oukan/angular-image-compress
您可以从https://github.com/oukan/angular-image-compress找到更多详细信息
#2
0
set req headers Content-Encoding: gzip
it will be compressed automatically
set req headers Content-Encoding:gzip会自动压缩
#1
4
I think ng-image-compress will solve your issue. To use this,
我认为ng-image-compress将解决您的问题。要用它,
- Download ng-image-compress
- 下载ng-image-compress
- Bower - bower install angular-image-compress.
- 凉亭 - 凉亭安装角度图像压缩。
- Include angular.js and angular-image-compress.js in your application and add ngImageCompress as dependency to your main module.
- 在应用程序中包含angular.js和angular-image-compress.js,并将ngImageCompress作为依赖项添加到主模块中。
angular.module('myApp', ['ngImageCompress']);
angular.module('myApp',['ngImageCompress']);
Then you can include "resize-max-height="800" resize-max-width="800" resize-quality="0.7" resize-type="image/jpg" ng-image-compress " in your File Type input to compress your image.
然后你可以在文件类型输入中包含“resize-max-height =”800“resize-max-width =”800“resize-quality =”0.7“resize-type =”image / jpg“ng-image-compress”压缩你的形象。
You can find more details from https://github.com/oukan/angular-image-compress
您可以从https://github.com/oukan/angular-image-compress找到更多详细信息
#2
0
set req headers Content-Encoding: gzip
it will be compressed automatically
set req headers Content-Encoding:gzip会自动压缩