elo's avatar
Level 3

Image URL works in local serve but fails in staging environment

Hi guys, I am working on an API application using Laravel 5.8 version. When a get request is made to the products api endpoint, I return a ProductResource collection which looks like this

public function toArray($request)
{
    return [
        'id'            => $this->id,
        'name'          => $this->name,
        'category'      => $this->category,
        'description'   => $this->description,
        'status'        => $this->status,
        'price'         => $this->price,
        'barrels'       => $this->barrels,
        'interest'      => $this->interest,
        'start'         => $this->start,
        'end'           => $this->end,
        'hidden'        => $this->hidden,
        'imageUrl'      => asset('storage/images/products/' . $this->image->name)
    ];
}

The challenge I am having is that on my local server clicking the returned imageUrl displays the correct image but in the staging environment, I get the default 404 not found page.

I created a symbolic link from public/storage to storage/app/public on my local server which i am developing on to store the actual image file before uploading the app file to the staging environment. A quick check of the storage/app/public/images/products in the staging environment shows the image file but I still cannot view it from my browser. What could be the possible reason for this behavior?

Here's a sample of the resource in both my local and staging environments

Local/development server

{
    "id": 17,
    "name": "test",
    "category": "test",
    "description": "test",
    "status": "test",
    "price": 10990,
    "barrels": 207736,
    "interest": 0.2,
    "start": "2019-07-25",
    "end": "2019-08-25",
    "hidden": 0,
    "imageUrl": "http://localhost:8000/storage/images/products/pramopro_test_17.jpeg"
  }

Staging server

{
    "id": 13,
    "name": "test prod",
    "category": "test prod category",
    "description": "test prod description",
    "status": "loading",
    "price": 10000,
    "barrels": 300000,
    "interest": 0.2,
    "start": "2019-07-22",
    "end": "2019-08-28",
    "hidden": 0,
    "imageUrl": "http://stagingurl/storage/images/products/staging_testprod_13.jpeg"
  }
0 likes
5 replies
Azik's avatar

in staging server run artisan command php artisan storage:link

elo's avatar
Level 3

I tried running the command via ssh but it does nothing. When I run php artisan it returns nothing but composer returns a list of the commands.

pedroroccon's avatar

Can you show us your output? Try typing php artisan --version just to check if artisan is working

elo's avatar
Level 3

It returns nothing

[staging]# php artisan --version
[staging]#

elo's avatar
elo
OP
Best Answer
Level 3

Very sorry guys. I forgot to copy the storage folder from public to public_html when I made updates and had to copy the entire app again to the staging server.

Please or to participate in this conversation.