In a dropzone, some of my images could not be uploaded and no toast error message was displayed.
In console, the error message is only 'File not provided'. But after investigation, the error was simply due to the exceeds of the upload_max_filesize ini directive: so the message returned by the server is not correct.
Proposed solution
Add a toast message on error inside Dropzone.vue
Replace FileUploadController::upload from :
public function upload(Request $request): JsonResponse {
// "hasFile" does not take into account files that have errors
if ($request->hasFile('file')) {
$path = $request->file('file')->store('', ['disk' => 'uploads']);
return response()->json(['path' => $path], 200);
}
return response()->json(___('craftable-pro', 'File not provided'), 422);
}
to
public function upload(Request $request): JsonResponse {
if ($request->files->has('file')) {
$file = $request->files->get('file');
if ($file->isValid()) {
$path = $request->file('file')->store('', ['disk' => 'uploads']);
return response()->json(['path' => $path], 200);
} else {
$errorMessage = $file->getErrorMessage();
// TODO: add translation or log it ?
return response()->json($errorMessage, 422);
}
}
return response()->json(___('craftable-pro', 'File not provided'), 422);
}
Issue
In a dropzone, some of my images could not be uploaded and no toast error message was displayed. In console, the error message is only 'File not provided'. But after investigation, the error was simply due to the exceeds of the upload_max_filesize ini directive: so the message returned by the server is not correct.
Proposed solution
Dropzone.vue
Replace
FileUploadController::upload
from :to