skip to Main Content

my issue with FilePond is when I upload multiple images it سeparates the requests, which prevents me from uploading the images to one folder.

Here is my input field:

<input type="file" id="imgs" name="imgs" accept="image/jpeg"
   multiple
   data-allow-reorder="true"
   data-max-file-size="3MB"
   data-max-files="5"
>

Here is my controller code:

public function saveTemp(Request $request)
{
    if ($request->only('imgs')) {
        $file = $request->file('imgs');
        $fileName = $file->getClientOriginalName();
        $folder = uniqid().'-'.now()->timestamp;
        $file->storeAs('admin/product/tmp-images/tmp-'.$folder, $fileName);

        return $folder;
    }

    return '';
}

there is no documentation from FilePond about file validating.
appreciate the help.

2

Answers


  1. Chosen as BEST ANSWER

    For validate part you can go back to @mrkazmierczak answer.

    but for filepond requests that is how filepond behaves, I`ve made my own file uploader using vue.js with a live image preview.

    if you want the source code feel free to ask.


  2. If you are using only FilePond upload script without any JS framework, so you can’t use validation plugin provided with FilePond. The only way you can pass this is validation on the backend is

    $request->validate([
        'file' => 'required|mimes:png,jpg,jpeg|max:2048'
    ]);
    

    But think about any frontend framework and use FilePond validation plugin. This solution is more reactive. Of course you still need to validate what you have on frontend and backend at the same time, but but this is more user friendly.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search