I was able to get q-file to upload a single image and my Laravel API is handling it perfectly. Of course I need multiple files uploaded at once so I'm trying to switch to q-uploader and when I log the response the file shows as [object File].
I also tried using $request->file('attachment') in the FileController but it returns null.
<q-uploader
:factory="uploadFactory"
label="Upload Images/Files"
color="primary"
multiple
/>
Then in my FileController.php:
public function upload(Request $request) {
\Log::info($request);
}
returns:
array (
'attachment' => '[object File]',
'fileable_type' => 'App\\Task',
'fileable_id' => '27375',
'vessel_id' => '1',
)
My factory to upload:
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)
}
})
})
},
When I try this with the 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>
It works and here's what I'm logging in Laravel for the request:
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,
)),
)