1
0
mirror of https://github.com/24eme/signaturepdf.git synced 2023-08-25 09:33:08 +02:00

upload depuis l'url d'un pdf

This commit is contained in:
Vincent LAURENT 2021-11-02 01:18:13 +01:00
parent e4947e6a20
commit 2e01794fff

View File

@ -31,6 +31,26 @@
document.getElementById('input_pdf_upload').addEventListener('change', function(event) {
document.getElementById('form_pdf_upload').submit();
});
async function uploadFromUrl(url) {
var response = await fetch(url);
if(response.status != 200) {
return;
}
var pdfBlob = await response.blob();
if(pdfBlob.type != 'application/pdf' && pdfBlob.type != 'application/octet-stream') {
return;
}
var dataTransfer = new DataTransfer();
var filename = url.replace(/^.*\//, '');
dataTransfer.items.add(new File([pdfBlob], filename, {
type: 'application/pdf'
}));
document.getElementById('input_pdf_upload').files = dataTransfer.files;
document.getElementById('input_pdf_upload').dispatchEvent(new Event("change"));
}
if(window.location.hash) {
uploadFromUrl(window.location.hash.replace(/^\#/, ''));
}
</script>
</body>
</html>