emergingdzns - 4 months ago

I've got a client site and it runs very well most of the time. Every once in a while though it will display the broken image icon where an image should be. This only affects images that were added to the Files module (either manually in the admin panel or via the file field type). I looked at the console inspector and it says that the image is a 500 error. The image does in fact exist and if I reload the page, the image shows up. I can't figure out why this is happening. It makes no sense to me. Any thoughts?

Answer

ryanthompson - 4 months ago

Ya you wanna do this: cart.product.product_image[0].make.path and skip the /files part.

Currently you are serving images through PHP which is a no-go for use like this.

The way I just showed you will use static resources so your server can leverage caching / efficiency as normal.

ryanthompson - 4 months ago

How are you loading the images? Sounds like you might be loading them over PHP.

For files - based on the file instance - DONT use route('view') or .url - use file.make.path (or url) but make pushes it into the image instance and caches static files.

Post some URLs and we can get a better idea of what's up.

emergingdzns - 4 months ago

I'm using the path variable. Here's an excerpt of the code in the loop for the cart objects in the shopping cart I built (for the images I used the files field type): <img src="/files/{{ cart.product.product_image[0].path }}">. Here's an image address (though you won't be able to see it because the site is locked down at the moment behind an http auth at the client's request): https://dev.doctorherdman.com/files/images/Eskimopureefa.jpg As I mentioned it will show up broken but then after I refresh it's just fine. It's perplexing.

ryanthompson - 4 months ago

Ya you wanna do this: cart.product.product_image[0].make.path and skip the /files part.

Currently you are serving images through PHP which is a no-go for use like this.

The way I just showed you will use static resources so your server can leverage caching / efficiency as normal.

ryanthompson - 4 months ago

https://pyrocms.com/documentation/files-module/2.4/usage/files#fileinterface-image

And make() mentioned later are what you wanna do.