简体   繁体   中英

Compress image at client side (angularjs) and upload to server(nodejs)

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.

I think ng-image-compress will solve your issue. To use this,

  • Download 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.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.

You can find more details from https://github.com/oukan/angular-image-compress

设置req标头Content-Encoding: gzip它将被自动压缩

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM