Implémentation des options de téléversement

This commit is contained in:
Breizh 2021-05-08 23:16:09 +02:00
parent 0c29e928bc
commit 144293faf2
2 changed files with 14 additions and 6 deletions

View file

@ -27,13 +27,11 @@
<input id="submitbtn" type="submit" value="Téléverser"> <input id="submitbtn" type="submit" value="Téléverser">
</p> </p>
<!-- <p id="expiry" class="jsonly" style="display: none;"> --> <p id="expiry" class="jsonly" style="display: none;">
<p id="expiry" style="display: none;">
<label for="expiration">Expiration du fichier :</label> <label for="expiration">Expiration du fichier :</label>
<input type="number" id="expiration" min="1" max="30" /> jour(s) <input type="number" id="expiration" min="1" max="30" /> jour(s)
</p> </p>
<!-- <p id="maxdownload" class="jsonly" style="display: none;"> --> <p id="maxdownload" class="jsonly" style="display: none;">
<p id="maxdownload" style="display: none;">
<label for="maxdl">Nombre maximal de téléchargements :</label> <label for="maxdl">Nombre maximal de téléchargements :</label>
<input type="number" id="maxdl" min="1" /> <input type="number" id="maxdl" min="1" />
</p> </p>

View file

@ -6,7 +6,7 @@ document.getElementById('fileinput').setAttribute('multiple','');
// get form // get form
const form = document.getElementById('dropzone'); const form = document.getElementById('dropzone');
function upload(file) { function upload(file,exp,maxdl) {
// create the XHR // create the XHR
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
@ -28,6 +28,14 @@ function upload(file) {
// create and send the request // create and send the request
xhr.open('PUT', '/' + file.name); xhr.open('PUT', '/' + file.name);
// add headers
if (exp != "") {
xhr.setRequestHeader('Max-Days',exp);
}
if (maxdl != "") {
xhr.setRequestHeader('Max-Downloads',maxdl);
}
// send file
xhr.send(file); xhr.send(file);
} }
@ -38,9 +46,11 @@ form.addEventListener('submit', e => {
// get file list // get file list
const files = document.getElementById('fileinput').files; const files = document.getElementById('fileinput').files;
const exp = document.getElementById('expiration').value;
const maxdl = document.getElementById('maxdl').value;
// upload each file // upload each file
for (let i = 0; i < files.length; i++) { for (let i = 0; i < files.length; i++) {
upload(files[i]); upload(files[i],exp,maxdl);
} }
}); });