Create Imported Image Validation Function
Context
When importing images, we would like to be reasonably sure that all imported images are whole and unharmed, In practical terms, this means that images retrieved from the database as well as their on-disk representation are valid.
Possible Approaches
Crane
crane is a popular utility that can validate images. We could use this tool alongside the import process in an off the shelf manner.
Internal Tooling
crane
uses this package from Google to perform its validation. We could use this library directly inside the import tool to perform validation.
Reuse Existing API Validators
We already validate images before storing them, it's possible we could reuse the code that does this. The external validation options mentioned above are more rigorous in some respects, but even then it may be beneficial to use the same logic throughout.
Invalid and Importable Images
It's possible we'll encounter invalid data at rest that is still able to imported. For example, the API validator may return errors if the image has too many references. In this case, we'll need to decide how to handle these images.