You can request the file from local filesystem as a Blob
using XMLHttpRequest()
or fetch()
utilize FileReader
to convert the Blob
to a data URI
, set the .href
property of an <a>
element to path to server with query string where data URI
is value of query, call .click()
on <a>
element. At server process query string parameters at GET
request to process data URI
representation of file.
const a = document.createElement("a");
document.body.appendChild(a);
const reader = new FileReader;
reader.onload = () => {
a.href = `/path/to/server?file=${reader.result}`;
a.click();
}
fetch("/path/to/local/file")
.then(response => response.blob())
.then(blob => reader.readAsDataURL(blob))
.catch(err => console.error(err));