我能够获取 q-file 来上传单个图像,并且我的 Laravel API 可以完美地处理它。当然,我需要一次上传多个文件,所以我尝试切换到 q-uploader,当我记录响应时,文件显示为 [object File]。
我也尝试在 FileController 中使用 $request->file('attachment') 但它返回 null。
<q-uploader
:factory="uploadFactory"
label="Upload Images/Files"
color="primary"
multiple
/>
然后在我的 FileController.php 中:
public function upload(Request $request) {
\Log::info($request);
}
返回:
array (
'attachment' => '[object File]',
'fileable_type' => 'App\\Task',
'fileable_id' => '27375',
'vessel_id' => '1',
)
我的工厂要上传:
uploadFactory (file) {
let data = new FormData()
data.append('attachment', file)
data.append('fileable_type', 'App\\Task')
data.append('fileable_id', this.task.id)
data.append('vessel_id', this.vessel.id)
return new Promise((resolve, reject) => {
this.$axios.post('/api/file/upload', data, { headers: { 'Content-Type': 'multipart/form-data' } }).then(response => {
console.log(response)
resolve(null)
}).catch(error => {
if (error) {
console.log(error)
}
})
})
},
当我用 q-file 尝试这个时:
<q-file color="primary" v-model="attachments" label="Images/Files" outlined>
<template v-slot:prepend>
<q-icon name="attach_file" />
</template>
<template v-slot:after v-if="canUpload">
<q-btn
color="primary"
dense
icon="cloud_upload"
round
@click="submitFiles"
:disable="!canUpload"
:loading="isUploading"
/>
</template>
</q-file>
它有效,这就是我在 Laravel 中为请求登录的内容:
array (
'fileable_type' => 'App\\Task',
'fileable_id' => '27375',
'vessel_id' => '1',
'attachments' =>
Illuminate\Http\UploadedFile::__set_state(array(
'test' => false,
'originalName' => 'IMG_0126.jpg',
'mimeType' => 'image/jpeg',
'error' => 0,
'hashName' => NULL,
)),
)