Commit ecfbca9f by Johannes

Support multifile upload via the webinterface

1 parent 5be531a3
Showing with 17 additions and 6 deletions
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,7 @@
<div class="col-lg-12"> <div class="col-lg-12">
<center> <center>
<form id="fileUploadForm"> <form id="fileUploadForm">
<input type="file" v-el:upload style="display: none" id="uploadInput"/> <input type="file" v-el:upload style="display: none" id="uploadInput" multiple/>
<button class="btn btn-primary" v-on:click.stop.prevent="upload()" id="uploadButton">Upload</button> <button class="btn btn-primary" v-on:click.stop.prevent="upload()" id="uploadButton">Upload</button>
</form> </form>
</center> </center>
......
...@@ -129,21 +129,32 @@ function upload() { ...@@ -129,21 +129,32 @@ function upload() {
// detach event handler // detach event handler
$(app.$els.upload).off('change'); $(app.$els.upload).off('change');
var file = app.$els.upload.files[0]; var length = app.$els.upload.files.length;
var done = 0;
function uploadFile(file) {
var path = encode(sanitize(app.path + '/' + file.name)); var path = encode(sanitize(app.path + '/' + file.name));
var formData = new FormData(); var formData = new FormData();
formData.append('file', file); formData.append('file', file);
superagent.put('/api/files' + path).query({ username: app.session.username, password: app.session.password }).send(formData).end(function (error, result) { superagent.put('/api/files' + path).query({ username: app.session.username, password: app.session.password }).send(formData).end(function (error, result) {
app.busy = false;
if (result && result.statusCode === 401) return logout(); if (result && result.statusCode === 401) return logout();
if (result && result.statusCode !== 201) return console.error('Error uploading file: ', result.statusCode); if (result && result.statusCode !== 201) console.error('Error uploading file: ', result.statusCode);
if (error) return console.error(error); if (error) console.error(error);
++done;
if (done >= length) {
app.busy = false;
refresh(); refresh();
}
}); });
}
for(var i = 0; i < length; i++) {
uploadFile(app.$els.upload.files[i]);
}
}); });
// reset the form first to make the change handler retrigger even on the same file selected // reset the form first to make the change handler retrigger even on the same file selected
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!