You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 :
publicfunctionupload(Request$request): JsonResponse {
// "hasFile" does not take into account files that have errorsif ($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
publicfunctionupload(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);
}
The text was updated successfully, but these errors were encountered:
senecolas
changed the title
No error handling in files FileUploadController.php and Dropzone.vue
No error handling in FileUploadController.php and Dropzone.vue
Apr 19, 2023
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
FileUploadController::upload
from :to
The text was updated successfully, but these errors were encountered: