Allow images and detection upload for future data #56
@@ -422,7 +422,7 @@
|
|||||||
}
|
}
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
loadImage.then((imageData) => {
|
loadImage.then(() => {
|
||||||
this.imageLoaded = true
|
this.imageLoaded = true
|
||||||
this.resultData = {}
|
this.resultData = {}
|
||||||
this.resetView()
|
this.resetView()
|
||||||
@@ -437,7 +437,7 @@
|
|||||||
box.style.display = 'none'
|
box.style.display = 'none'
|
||||||
},
|
},
|
||||||
submitData () {
|
submitData () {
|
||||||
this.uploadData(this.imageView.split(',')[1])
|
this.uploadData(this.imageView.split(',')[1],this.resultData.detections)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { f7 } from 'framework7-vue'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
methods: {
|
methods: {
|
||||||
newUid (length) {
|
newUid (length) {
|
||||||
@@ -9,27 +11,53 @@ export default {
|
|||||||
}
|
}
|
||||||
return uid.join('')
|
return uid.join('')
|
||||||
},
|
},
|
||||||
uploadData (imagePayload) {
|
uploadData (imagePayload, classPayload) {
|
||||||
/*****
|
let uploadImage =new Promise(resolve => {
|
||||||
* This is the curl statement which works:
|
const dataUid = this.newUid(16)
|
||||||
* curl -k -T file.ext -u "LKBm3H6JdSaywyg:" -H 'X-Requested-With: XMLHttpRequest' https://nextcloud.azgeorgis.net/public.php/webdav/newFile.ext
|
var byteChars = window.atob(imagePayload)
|
||||||
*
|
var byteArrays = []
|
||||||
* 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.
|
var len = byteChars.length
|
||||||
*
|
|
||||||
* Just need to work out:
|
for (var offset = 0; offset < len; offset += 1024) {
|
||||||
* 1) How that translates to a JS XHR
|
var slice = byteChars.slice(offset, offset + 1024)
|
||||||
* 2) Whether I've got another @#$% CORS issue with it
|
var byteNumbers = new Array(slice.length)
|
||||||
* Answer: Bleep! Bleeeeeep! Bleep! Bleep! Bleep!....yes.
|
for (var i = 0; i < slice.length; i++) {
|
||||||
*****/
|
byteNumbers[i] = slice.charCodeAt(i)
|
||||||
|
}
|
||||||
|
|
||||||
var xhr = new XMLHttpRequest()
|
var byteArray = new Uint8Array(byteNumbers)
|
||||||
var uploadUrl = `https://nextcloud.azgeorgis.net/public.php/webdav/${this.newUid(16)}.jpeg`
|
byteArrays.push(byteArray)
|
||||||
xhr.open("POST", uploadUrl)
|
}
|
||||||
xhr.setRequestHeader('Content-Type', 'image/jpeg')
|
var imageBlob = new Blob(byteArrays, {type: 'image/jpeg'})
|
||||||
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
|
|
||||||
xhr.setRequestHeader("Authorization", "Basic " + btoa("LKBm3H6JdSaywyg:"))
|
|
||||||
|
|
||||||
xhr.send(imagePayload)
|
var xhrJpg = new XMLHttpRequest()
|
||||||
|
var uploadUrl = `https://nextcloud.azgeorgis.net/public.php/webdav/${dataUid}.jpeg`
|
||||||
|
xhrJpg.open("PUT", uploadUrl)
|
||||||
|
xhrJpg.setRequestHeader('Content-Type', 'image/jpeg')
|
||||||
|
xhrJpg.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
|
||||||
|
xhrJpg.setRequestHeader("Authorization", "Basic " + btoa("LKBm3H6JdSaywyg:"))
|
||||||
|
xhrJpg.send(imageBlob)
|
||||||
|
|
||||||
|
var xhrTxt = new XMLHttpRequest()
|
||||||
|
var uploadUrl = `https://nextcloud.azgeorgis.net/public.php/webdav/${dataUid}.txt`
|
||||||
|
xhrTxt.open("PUT", uploadUrl)
|
||||||
|
xhrTxt.setRequestHeader('Content-Type', 'text/plain')
|
||||||
|
xhrTxt.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
|
||||||
|
xhrTxt.setRequestHeader("Authorization", "Basic " + btoa("LKBm3H6JdSaywyg:"))
|
||||||
|
xhrTxt.send(JSON.stringify(classPayload))
|
||||||
|
|
||||||
|
resolve()
|
||||||
|
})
|
||||||
|
uploadImage.then(() => {
|
||||||
|
var toast = f7.toast.create({
|
||||||
|
text: 'Detections Uploaded: thank you.',
|
||||||
|
closeTimeout: 2000
|
||||||
|
})
|
||||||
|
toast.open()
|
||||||
|
}).catch((e) => {
|
||||||
|
console.log(e.message)
|
||||||
|
f7.dialog.alert(`Error uploading image: ${e.message}`)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user