M
M
Maks Kovyvchak2020-05-29 16:15:12
JavaScript
Maks Kovyvchak, 2020-05-29 16:15:12

How to download a file from another host to a client?

Tell me the easiest way to have a link to a file (for example,

some-host-name/file.pdf
) from an external host, make a jump on your client (the project is written in angular)
thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Robur, 2020-05-29
@Robur

put it in the href of the a tag

G
GrayHorse, 2020-05-29
@GrayHorse

const response = await fetch(url);
const blob = await response.blob();
const a = document.createElement("a");
a.download = ""; // name
a.href = URL.createObjectURL(blob);
a.click();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question