fix(Gallery): send substring to API when it's a video

This commit is contained in:
Matthieu Bessat 2020-09-02 22:58:57 +02:00
parent 20adf407f0
commit 2020e79cab

View file

@ -262,7 +262,11 @@ export default {
const reader = new FileReader()
reader.readAsArrayBuffer(file)
reader.onloadend = (event) => {
resolve(['file', event.target.result, file.name])
let name = file.name
if (file.type.indexOf('video') !== -1) {
name += '||%_FORMAT_VIDEO_%||' // it's a dirty way to say to the back end : 'hey this is a video file !'
}
resolve(['file', event.target.result, name])
}
reader.onerror = () => {
console.log(reader.error)
@ -275,7 +279,11 @@ export default {
const promises = this.files.map(file => this.loadFile(file))
Promise.all(promises).then(results => {
const formData = new FormData()
results.forEach(r => formData.append(r[0], new Blob([new Uint8Array(r[1])]), r[2]))
results.forEach(r => formData.append(
r[0], // field name
new Blob([new Uint8Array(r[1])]), // the file
r[2] // file name
))
this.$apitator.post('/delegate/medias', formData, {
withAuth: true,