Search code examples
javascriptangularfile-uploadangular7angular8

Can a large file be compressed before upload from UI in angular?


Is there any way to compress a file before upload from front end? I have a very large file to upload which takes so much of time. I am looking for a way to reduce the time for the upload.


Solution

  • How about using html-to-image plugin to convert image to lower quality and then apply upload as you are doing.

    npm install --save html-to-image

    You can try other htmlToImage method, up to you. What I have used is below:

    htmlToImage.toJpeg(node, { quality: 0.95 }).then(function (dataUrl) {
      let link = document.createElement('a');
      link.download = "page" + '.jpeg';
      link.classList.add("specialanchor")
      link.href = dataUrl;
      link.click();
    }).catch(function (error) {
      // console.error('oops, something went wrong!', error);
    });
    

    To learn more: https://www.npmjs.com/package/html-to-image