Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rhand's avatar
Level 6

Loaded Thumbnails hit 404

We have been implementing a new way to get project data using the database instead of the session data. This to allow for loading multiple project in different browser tabs. Now we are however updating a lot of requests to include a project id string. The media manager no longer is loading the thumbnails properly resulting in 404s. It is using a lazyLoading.vue component with this method

...
methods: {
    sendDimensionsToParent() {
      const manager = this
      let url = this.src

      // Load thumbnail image instead original
      if (!this.src.match(/.svg$/)) {
        this.src = `/editor/image-thumbnails?path=${this.src.replace(location.origin + '/uploads/', "")}`
      }

      this.$refs.img.addEventListener('load', function() {
        manager.applyStyles = true
        manager.$el.style.border = 'none'

        if (!manager.checkForDimensions(url)) {
          EventHub.fire('save-image-dimensions', {
            url: url,
            val: `${this.naturalWidth} x ${this.naturalHeight}`
          })
        }
      })
    }
  },
...

The thumbnail calls ask for urls like https://site.test/editor/image-thumbnails?path=https://site.test/uploads/2/380_icons.png and hit a 404 error now. The query string path https://site.test/uploads/2/380_icons.png does load data but that is not the thumbnail .

Perhaps we need to update the ProjectController method

...
public function getThumbnailImage()
    {
        $path = request()->path;
        // File not exists
        if (! Storage::disk('public_upload')->exists($path)) {
            abort(404);
        }

        if (preg_match("/\.svg/", $path) || preg_match("/\.tiff/", $path)) {
            return response()->file(public_path('/uploads/'.$path), [
                'Cache-control' => 'public',
            ]);
        }

        // Generate thumbnail with width 50px when thumbnail not found
        if (! Storage::disk('public_upload')->exists('thumbnails-'.$path)) {
            $image = Image::make(public_path('uploads/'.$path));
            $image->orientate();
            $image->resize(50, null, function ($constraint) {
                $constraint->aspectRatio();
            });

            Storage::disk('public_upload')->put('thumbnails-'.$path, (string) $image->encode('jpg'));
        }

        return response()->file(public_path('uploads/thumbnails-'.$path), [
            'Cache-control' => 'public',
        ]);
    }
}
...

and add ?project=${PROJECT_ID} like we have been doing for other Axios calls like axios.get(/editor/get-pages?project=${PROJECT_ID}) . But been trying a few options and still do not get the thumbnails generated and loaded properly.

this.src = `/editor/image-thumbnails?path=${this.src.replace(location.origin + '/uploads/', "" + `?project=${PROJECT_ID}`)}`

creates https://site.test/editor/image-thumbnails?path=?project=22/380_cookie-bar.png and still 404s so that is not correct either.

same for

this.src = `/editor/image-thumbnails?path=${this.src.replace(location.origin + '/uploads/', "") + `?project=${PROJECT_ID}`}`

which generates URL: https://site.test/editor/image-thumbnails?path=2/380_formsettingsfive.png?project=2 and still is a 404

0 likes
5 replies
rhand's avatar
Level 6

Trying to dd the path. Could not figure out how to do this in the controller so tried this in the view

@php $path = request()->path; 
@dd($path);

but variable is not defined this way.

Sinnbeck's avatar

@rhand You can do it in the controller

dd(request()->input('path'));
1 like
rhand's avatar
rhand
OP
Best Answer
Level 6

@Sinnbeck Thanks a lot for that. Tried a direct dd() inside method but it did not fire at all.

Thanks to some help by a senior developer I found out I needed

...
 this.src = `/editor/image-thumbnails?project=${PROJECT_ID}&path=${this.src.replace(location.origin + '/uploads/', "")}`
...

I needed &path . Had no clue...

Please or to participate in this conversation.