Add upload function

Signed-off-by: Justin Georgi <justin.georgi@gmail.com>
This commit is contained in:
2023-12-16 17:10:00 -07:00
parent c5b4bc5788
commit ffa04dc3c7
2 changed files with 23 additions and 1 deletions

View File

@@ -437,7 +437,7 @@
box.style.display = 'none'
},
submitData () {
alert(this.newUid(12))
this.uploadData(this.imageView.split(',')[1])
}
}
}

View File

@@ -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)
}
}
}