Hello!
I am using Laravel 9 with Uppy. I have an issue that when the upload is successful, the file isn’t actually stored in the destination:
I have a global file upload action that runs across the entire application:
class UploadImageAction implements UploadImageContract
{
public function handle(Request $request, $imageProperty, $image, $imageDir)
{
if ($request->hasFile($imageProperty)) {
// Handle uploading lf_image
if (!is_null($image) && Storage::exists($image)) {
// Throw exceptions here
Storage::delete($image);
}
// Throw exceptions here
return $request->file($imageProperty)->store($imageDir);
}
}
}
It was working fine before adding Uppy to the project, but I don’t know why the file/s aren’t being uploaded?
The files are being stored together with the form data in the controller like so:
public function storeReport(Request $request)
{
$report = new Report();
$report->fill($request->validated());
$report = $this->handleAttachments($request, $report); // Upload Image Action class here
$report->save();
if(!$report) {
throw new ReportException('Something went wrong with the request.' . $report);
}
return $report;
}
The files should show at public/app/report/attachments
This is the Uppy code:
uppy.use(Uppy.Form, {
target: '#reportsForm',
resultName: 'uppyResult',
getMetaFromForm: true,
submitOnSuccess: false,
triggerUploadOnSubmit: false,
});
uppy.use(Uppy.XHRUpload, {
endpoint: storeReport,
limit: 10,
formData: true,
fieldName: 'attachment',
allowedMetaFields: null,
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});