phpangularlaraveldingo-api

Laravel response 404 file not found


I'm using Dingo/API and this is a transformer that returns me data

return [
            'id' => $site->id,
            'path' => asset($site->path),
            'siteLink' => $site->site_link,
            'features' => $features,
        ];

Generated link looks good, however when I try to access it from my Angular app it's said that

Failed to load resource: the server responded with a status of 404 (Not Found) http://api.example.com/public/thumbnails/ySOSYhaCCRcH3t9agsco3ToUwoHxMZJ3r1PhEHlM.jpeg


Solution

  • The solution.

    In filesystems.php local disk was specified as a default disk. According to docs local disk is supposed to be invisible for public and stored inside storage/app. Thus I was trying to save my file using local disk and accessing it with path public/....

    Option #1

    Change in filesystems.php default disk to public and use Storage::url() to get url to image.

    Option #2

    Use $file->store('path', 'public') and Storage::disk('public')->url('path')

    So that used disk is specified explicitly.

    The given path will contain link close to http://example.com/storage/path.