1
0
Fork 0
mirror of https://github.com/24eme/signaturepdf synced 2024-06-04 15:02:29 +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>