Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No error handling in FileUploadController.php and Dropzone.vue #26

Open
senecolas opened this issue Apr 19, 2023 · 1 comment
Open

No error handling in FileUploadController.php and Dropzone.vue #26

senecolas opened this issue Apr 19, 2023 · 1 comment
Assignees

Comments

@senecolas
Copy link

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

  • 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);
}
@senecolas 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
@palypster
Copy link
Contributor

Thank you, we're gonna have a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants