sumit
sumit

Reputation: 11

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.

Upvotes: 0

Views: 4454

Answers (2)

Shoma
Shoma

Reputation: 499

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

Upvotes: 1

Job
Job

Reputation: 485

There are a handful of file compression libraries, like wasm-flate or JSCompress. If you Google this, you should get quite a few hits that can help you with file compression in the browser.

Upvotes: -1

Related Questions