silverstripe-cloudassets icon indicating copy to clipboard operation
silverstripe-cloudassets copied to clipboard

Disappearing Images

Open ryanbadger opened this issue 8 years ago • 3 comments

I'm not sure if anybody else has had this issue, but for me, as soon as my EC2 instance rebooted or scaled, images were lost.

I tracked it down to line 122 of CloudImage, the getFormattedImage function (Worth also adding to the doc that this ONLY works with that perhaps? E.G - CroppedImage etc all just fall back to standard Image.)

So that line seems to check if the file exists locally before doing anything else, which in most cases, it doesn't.

    if ($this->ID && $this->Filename && Director::fileExists($this->Filename)) {

I changed that to

    if ($this->ID && $this->Filename)) {

and now this works fine for me. As soon as I clear my assets folder on disk, it downloads every item again from S3, then resamples them and stores them correctly.

ryanbadger avatar Nov 16 '16 09:11 ryanbadger

Brilliant. Any chance you'd be willing to submit that as a PR?

markguinn avatar Nov 16 '16 17:11 markguinn

Sure, but it may be better to add a better check here instead, I wrote an old S3 module for SS2.4 which checked the headers were 200 on S3 files before trying to use them, might be worth adding that in here too?

Ah actually, it looks like you already check for missing remote image further down anyway, so probably fine as it is. Will create a PR now, can you grant me access?

ryanbadger avatar Nov 16 '16 23:11 ryanbadger

Another issue I saw was that when my app auto scales or I deploy, the cached images are of course lost, but the DB CloudImageCachedStore still tells SilverStripe they exist, so they aren't regenerated.

I'm sure a quick check in the code for file_exists would fix this, but as a hack I just run a post deploy script on my app to do a flush=all

And that clears the cache whenever I deploy to my site, or it autoscales. Not sure if this will work when there are more than 1 instance running at once... but it's better than nothing.

ryanbadger avatar Nov 29 '16 08:11 ryanbadger