How to restore missing S3 images from post

One of my posts has randomly lost its images. I ran PostCustomField.where(name: Post::MISSING_UPLOADS) in the rails console and got this:

  id: 7335,
  post_id: 36,
  name: "missing uploads",
  created_at: Tue, 18 Feb 2020 17:44:40 UTC +00:00,
  updated_at: Tue, 18 Feb 2020 17:44:40 UTC +00:00>,

Since it’s only 14 images in a single post, I’m okay with fixing it manually but I have no idea how to find the original images in my S3 bucket. I’ve tried searching for the filenames here, but didn’t get any results:

I don’t use S3 per se, but wouldn’t your images not being there cause them to be missing?

Legit: are there logs you can check for those file names? Maybe something weird deleted them programmatically?

The problem is that the S3 web console only seems to search in the current folder. If I drill down to a specific folder and search for a file that is inside it, it finds it. If I go up to the parent folder, it doesn’t find it.

1 Like

You need to convert the upload:// urls into actual file names first.


Thanks, Michael. That would be useful, but I can’t figure out how to get the full path. In the rails console, I can do this but it doesn’t give me the actual filename:

=> "955952cf3952d2fad7c24528c08cfb79301a6260"

It depends on a lot of things but since the file is reportedly missing it might be in the wrong place anyway. Now that you know the filename it’s not much work to browse through s3 and see if you find a matching file.

You could also try to find an Upload in the database where the sha1 matches this string, and the upload record has a path. But again: if everything was alright then we wouldn’t be discussing this issue.