First of all, i've checked questions file-upload-in-vuetify and vuetify-file-uploads. But the solutions there didn't work.
I'm trying to use vuetify 2 <v-file-input>
to send multiple PDF files. I created the FormData
object and appended all my files but when i attempt to submit it doesn't reach my backend. I just get an empty object. this is my code:
Template:
<v-layout>
<v-flex>
<v-file-input show-size counter chips multiple label="Arquivo Geral" ref="myfile" v-model="files"></v-file-input>
</v-flex>
<v-flex>
<v-btn color="primary" text @click="submitFiles">test</v-btn>
</v-flex>
</v-layout>
script:
data() {
return {
files: null,
}
}
methods: {
submitFiles(){
let formData = new FormData()
if(this.files){
for( let file in this.files){
formData.append("cave", file)
}
console.log(formData.getAll("cave"))
console.log(this.files)
axios.post('https://eniwp6w65oc77.x.pipedream.net/',
{
files: formData,
test: "test"
},
{
headers: {
'Content-Type': 'multipart/form-data'
}
}).then( response => {
console.log('Success!')
console.log({response})
}).catch(error => {
console.log({error})
})
}
else {
console.log('there are no files.')
}
}
}
my response body and header in requestbin:
body:
{
"files": {},
"test": "test"
}
header:
host: eniwp6w65oc77.x.pipedream.net
Accept: application/json, text/plain, */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en-US,en;q=0.9,pt;q=0.8,gl;q=0.7
Cache-Control: no-cache
Content-Type: multipart/form-data
Origin: http://localhost:8000
Pragma: no-cache
Referer: http://localhost:8000/
Sec-Fetch-Mode: cors
Sec-Fetch-Site: cross-site
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
Content-Length: 28
Connection: keep-alive
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…