Dropzone js parallel upload causes problems in backend

196 views Asked by At

I'm currently building a system, where users can upload images to their ads. Each ad can have 8 images associated. One of those images become the primary image, which is display in search results and so on. When I upload multiple images using parallel and count the already existing records in db, to make sure that the limit aren't reached, things get weird. Because all images hit the server at the same time, they all passes the check to make sure, that you only upload 8 images and they are all uploaded suddenly. Everything works fine, if the user just upload one image at a time.

I don't know how to come along this bug. What is best practice ?

I'm using Laravel 5, just in case...

Thanks!

public function store(UploadAdImageRequest $request, $id)
{
    $ad = $this->adRepo->getWithImages($id);

    $this->imageRepo->hasSpace($ad);

    $image = $this->imageRepo->upload($request->file('image')->getRealPath(), $ad);

}
0

There are 0 answers