这是我的HTML:
<label class="btn btn-outline-info" v-if="plan">
<i class="fas fa-cloud-upload-alt"></i> Upload Appraisal<input type="file" id="file" ref="file" v-on:change="handleFilesUpload()" hidden>
</label>
这是我的javascript:
handleFilesUpload(){
this.file = this.$refs.file.files[0]
let formData = new FormData()
formData.append('appraisal', this.file)
this.uploadAppraisal(formData)
},
uploadAppraisal(data) {
axios.post( '/api/test',
data, {
headers: {
'Content-Type': 'multipart/form-data'
}
}
).then(response => {
this.info = response.data
})
.catch(function(){
console.log('FAILURE!!')
});
}
在后端,我正在运行Laravel Spark。我期待收到一个名为评估的文件。但是,当我这样做时,我得到了错误:
if ($request->hasFile('appraisal')) {
//
}
所以我有点困惑。我正在提交xml文件,此时我只是尝试对它们进行json编码并返回该结果。我想我做得对,但可能会关闭。任何帮助表示赞赏。快速说明:$ request-&gt;评估确实存在,据我所知,它只是空的。
以下是我的api中print_r($ request-&gt; all())的结果:
数组([appraisal] =&gt; Illuminate \ Http \ UploadedFile对象([test:Symfony \ Component \ HttpFoundation \ File \ UploadedFile:private] =&gt; [originalName:Symfony \ Component \ HttpFoundation \ File \ UploadedFile:private ] =&gt; test.xml [mimeType:Symfony \ Component \ HttpFoundation \ File \ UploadedFile:private] =&gt; application / octet-stream [size:Symfony \ Component \ HttpFoundation \ File \ UploadedFile:private] =&gt; 0 [错误:Symfony \ Component \ HttpFoundation \ File \ UploadedFile:private] =&gt; 1 [hashName:protected] =&gt; [pathName:SplFileInfo:private] =&gt; [fileName:SplFileInfo:private] =&gt;)
谢谢!
答案 0 :(得分:0)
嗯,一些更深入的研究表明,我仍然需要在php.ini文件中更改我的最大上传大小和帖子大小。我做到了,现在工作得很好。