Get presigned upload token via ajax request

This commit is contained in:
richard-dds
2019-08-16 16:06:17 -04:00
parent b7f8152cc1
commit 7d1dfa1d0e
6 changed files with 25 additions and 20 deletions

View File

@@ -20,12 +20,6 @@ export default {
props: {
name: String,
token: {
type: Object,
},
objectName: {
type: String,
},
initialData: {
type: String,
},
@@ -52,8 +46,7 @@ export default {
}
},
created: function() {
this.uploader = buildUploader(this.token)
created: async function() {
emitEvent('field-mount', this, {
optional: this.optional,
name: this.name,
@@ -71,13 +64,12 @@ export default {
return
}
const response = await this.uploader.upload(file, this.objectName)
const uploader = await this.getUploader()
const response = await uploader.upload(file, this.objectName)
if (response.ok) {
this.attachment = e.target.value
this.$refs.attachmentFilename.value = file.name
this.$refs.attachmentObjectName.value = this.objectName
this.$refs.attachmentInput.disabled = true
this.$refs.attachmentObjectName.value = response.objectName
} else {
this.uploadError = true
}
@@ -111,6 +103,11 @@ export default {
this.uploadError = false
this.sizeError = false
},
getUploader: async function() {
return fetch('/upload-token')
.then(response => response.json())
.then(({ token }) => buildUploader(token))
},
},
computed: {