Commit 234b43c8 authored by jackie / Andrea Ida Malkah Klaura's avatar jackie / Andrea Ida Malkah Klaura
Browse files

implement simple file upload

parent b9f610ab
......@@ -158,7 +158,78 @@ export default {
alert('By the mighty witchcraftry of the mother of time!\n\nThis feature is not implemented yet.')
},
addFile: function () {
this.notYetImplemented()
var uri = process.env.VUE_APP_API_TANK + 'shows/' + this.shows[this.currentShow].slug + '/files'
if (this.addNewFileURI) {
//this.uploadSourceURI
this.notYetImplemented()
} else if (this.uploadSourceFile) {
axios.post(uri, { 'source-uri': encodeURI('upload://' + this.uploadSourceFile.name) }, {
withCredentials: true,
headers: { 'Authorization': 'Bearer ' + this.$parent.user.access_token }
}).then(response => {
this.startUpload(response.data.id)
this.fetchShows(this.shows[this.currentShow].slug)
}).catch(error => {
console.log('Error:')
console.log(error)
alert('Error: could not add the new file upload. See console log for details.')
})
} else {
alert('Something is wrong. You have choose to upload a file, but the corresponding file object does not exist.')
}
},
startUpload: function (id) {
var uri = process.env.VUE_APP_API_TANK + 'shows/' + this.shows[this.currentShow].slug + '/files/' + id + '/import'
axios.get(uri, {
withCredentials: true,
headers: { 'Authorization': 'Bearer ' + this.$parent.user.access_token },
params: {'wait-for': 'running'}
}).then(
this.upload(id)
).catch(error => {
console.log('Error:')
console.log(error)
alert('Error: could not start the file upload. See console log for details.')
})
},
upload: function (id) {
/*
* NOTE: there is no npm package for flow.js and importing it manually did not
* work so far. therefore this is commented out and we are using the simple
* upload method, until there is a nice npm package for flow.js or somone
* resolves this issue otherwise
var flow = new Flow({
target: process.env.VUE_APP_API_TANK + 'shows/' + this.shows[this.currentShow].slug + '/files/' + id + '/upload',
chunkSize: 100 * 1024,
prioritizeFirstAndLastChunk: true
})
flow.on('fileSuccess', function(file, message) {
console.log(file, message)
})
flow.on('fileError', function(file, message) {
console.log(file, message)
alert('Error: could not upload your file. See console log for details.')
})
flow.addFile(this.uploadSourceFile)
flow.upload()
*/
var uri = process.env.VUE_APP_API_TANK + 'shows/' + this.shows[this.currentShow].slug + '/files/' + id + '/upload'
//var reader = new FileReader()
//axios.put(uri, reader.readAsArrayBuffer(this.uploadSourceFile), {
axios.put(uri, this.uploadSourceFile, {
withCredentials: true,
headers: {
'Authorization': 'Bearer ' + this.$parent.user.access_token,
'Content-Type': 'application/octet-stream'
}
}).then(response => {
console.log('Sucessfully uploaded file. Response data:')
console.log(response.data)
}).catch(error => {
console.log('Error:')
console.log(error)
alert('Error: could not start the file upload. See console log for details.')
})
},
switchShow: function (index) {
// set the current show and its ID to whatever we want to switch to now
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment