From ffa04dc3c75c6ed76c6f28b5551975d9a5ee37fe Mon Sep 17 00:00:00 2001 From: Justin Georgi Date: Sat, 16 Dec 2023 17:10:00 -0700 Subject: [PATCH] Add upload function Signed-off-by: Justin Georgi --- src/pages/detect.vue | 2 +- src/pages/submit-mixin.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/pages/detect.vue b/src/pages/detect.vue index 06e74c1..e3f578c 100644 --- a/src/pages/detect.vue +++ b/src/pages/detect.vue @@ -437,7 +437,7 @@ box.style.display = 'none' }, submitData () { - alert(this.newUid(12)) + this.uploadData(this.imageView.split(',')[1]) } } } diff --git a/src/pages/submit-mixin.js b/src/pages/submit-mixin.js index 2571f5a..1506d86 100644 --- a/src/pages/submit-mixin.js +++ b/src/pages/submit-mixin.js @@ -8,6 +8,28 @@ export default { uid.push(uidChars.charAt(Math.floor(Math.random() * ((i < 4) ? 26 : 36)))) } return uid.join('') + }, + uploadData (imagePayload) { + /***** + * This is the curl statement which works: + * curl -k -T file.ext -u "LKBm3H6JdSaywyg:" -H 'X-Requested-With: XMLHttpRequest' https://nextcloud.azgeorgis.net/public.php/webdav/newFile.ext + * + * Also, curl --header "Content-Type: text/plain" --data-raw "simple_body" --trace-ascii website-data-raw.log "$website" might be an example of how to put in the jpeg data. + * + * Just need to work out: + * 1) How that translates to a JS XHR + * 2) Whether I've got another @#$% CORS issue with it + * Answer: Bleep! Bleeeeeep! Bleep! Bleep! Bleep!....yes. + *****/ + + var xhr = new XMLHttpRequest() + var uploadUrl = `https://nextcloud.azgeorgis.net/public.php/webdav/${this.newUid(16)}.jpeg` + xhr.open("POST", uploadUrl) + xhr.setRequestHeader('Content-Type', 'image/jpeg') + xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest') + xhr.setRequestHeader("Authorization", "Basic " + btoa("LKBm3H6JdSaywyg:")) + + xhr.send(imagePayload) } } } \ No newline at end of file