From 5aba377da807e9c4d3d082a7b7db0a65a8185576 Mon Sep 17 00:00:00 2001 From: Patrizio Bekerle <patrizio.bekerle@tugraz.at> Date: Wed, 15 Jul 2020 15:42:01 +0200 Subject: [PATCH] Start Nextcloud upload implementation (#14) --- .../src/dbp-nextcloud-file-picker.js | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/packages/file-handling/src/dbp-nextcloud-file-picker.js b/packages/file-handling/src/dbp-nextcloud-file-picker.js index 92f0110c..1cc95dd7 100644 --- a/packages/file-handling/src/dbp-nextcloud-file-picker.js +++ b/packages/file-handling/src/dbp-nextcloud-file-picker.js @@ -306,6 +306,36 @@ export class NextcloudFilePicker extends ScopedElementsMixin(DBPLitElement) { }); } + uploadFiles(files) { + files.forEach((fileData) => this.uploadFile(fileData)); + } + + uploadFile(fileData) { + this.statusText = "Uploading " + fileData.filename + "..."; + + console.log(fileData); + + // https://github.com/perry-mitchell/webdav-client#putfilecontents + this.webDavClient + .putFileContents(fileData.filename, f) + .then(contents => { + // create file to send via event + const file = new File([contents], fileData.basename, { type: fileData.mime }); + console.log("binaryFile", file); + + // send event + const data = {"file": file, "data": fileData}; + const event = new CustomEvent("dbp-nextcloud-file-picker-file-uploaded", + { "detail": data, bubbles: true, composed: true }); + this.dispatchEvent(event); + + this.statusText = ""; + }).catch(error => { + console.error(error.message); + this.statusText = error.message; + }); + } + /** * Returns the parent directory path * -- GitLab