Commit ecfbca9f by Johannes

Support multifile upload via the webinterface

1 parent 5be531a3
Showing with 23 additions and 12 deletions
......@@ -108,7 +108,7 @@
<div class="col-lg-12">
<center>
<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>
</form>
</center>
......
......@@ -129,21 +129,32 @@ function upload() {
// detach event handler
$(app.$els.upload).off('change');
var file = app.$els.upload.files[0];
var path = encode(sanitize(app.path + '/' + file.name));
var length = app.$els.upload.files.length;
var done = 0;
var formData = new FormData();
formData.append('file', file);
function uploadFile(file) {
var path = encode(sanitize(app.path + '/' + file.name));
superagent.put('/api/files' + path).query({ username: app.session.username, password: app.session.password }).send(formData).end(function (error, result) {
app.busy = false;
var formData = new FormData();
formData.append('file', file);
if (result && result.statusCode === 401) return logout();
if (result && result.statusCode !== 201) return console.error('Error uploading file: ', result.statusCode);
if (error) return console.error(error);
superagent.put('/api/files' + path).query({ username: app.session.username, password: app.session.password }).send(formData).end(function (error, result) {
if (result && result.statusCode === 401) return logout();
if (result && result.statusCode !== 201) console.error('Error uploading file: ', result.statusCode);
if (error) console.error(error);
refresh();
});
++done;
if (done >= length) {
app.busy = false;
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
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!