Thanks a lot @metalsadman I got it working now. This promise within a promise thing got me confused.
Should anyone be interested in the future, this is what works for me:
html
v-if="document.ShowUploadDialog"
ref="uploader"
:multiple="false"
:factory="uploadFile"
@added="added"
@finish="uploaded"
@uploaded="uploaded"
url="http://localhost:4444/upload"
color="white"
text-color="grey-5"
style="margin-top:10px; margin-left: 340px; max-width: 250px"
>
script
uploadFile (files) {
return new Promise((resolve, reject) => {
var myUploader = this.$refs.uploader[0]
var file = files[0]
var fileSrc
var fileData
var reader = new FileReader()
reader.readAsDataURL(file)
reader.onerror = err => console.error(`Failed to read file: ${err}`)
reader.onload = function () {
fileSrc = reader.result
fileData = fileSrc.substr(fileSrc.indexOf(',') + 1)
stitchClient.callFunction('uploadImageToS3', [fileData, 'elever-erp-document-store', file.name, file.type])
.then(result => {
alert('fatto')
console.log(file)
myUploader.removeFile(file)
resolve(files)
})
.catch(err => {
console.error(`Failed to upload file: ${err}`)
reject()
})
}
})
},