我想在我的 Nuxt.js 網站上使用 Axios 將檔案上傳到 S3 存盤桶。我已經管理了該部分以獲取預先簽名的 URL。當我嘗試將預簽名 URL 與 Postman 一起使用時,一切正常,但是當我嘗試使用 Axios 時,出現此錯誤:Uncaught (in promise) ReferenceError: Access is not defined.
這是我的代碼:
<template>
<v-file-input label="Select your file to upload" accept="image/*" v-model="myFile">
File to upload to S3
</v-file-input>
</template>
<script>
export default {
data() {
return {
myFile: null,
ApiGatewayUrl: "https://xxxxxx.execute-api.eu-central-1.amazonaws.com/"
}
},
methods: {
uploadFile() {
// get the pre-signed URL
this.$axios.get(this.ApiGatewayUrl, {
headers: {
Authorization: this.$auth.strategy.token.get()
}
}).then((response) => {
// now do a PUT request to the pre-signed URL
this.$axios.put(response.data, {
files: this.myFile
}, {
headers: {
[Content-Type]: 'multipart/form-data'
}
}).then((response) => {
this.setState({
statusCode: response.status,
})
})
})
}
}
}
</script>
當它與 Postman 一起作業時,我猜錯誤來自我的 Axios 配置。
uj5u.com熱心網友回復:
您指定的內容型別標題錯誤。
代替:
headers: {
[Content-Type]: 'multipart/form-data'
}
和:
headers: {
"Content-Type": "multipart/form-data"
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/348091.html
