in api/src/main/scala/com/gu/adapters/http/Image.scala [38:50]
def validate(image: Array[Byte]): Either[Error, String] = {
// guessContentTypeFromStream only works with streams than support mark and reset
val is = new ByteArrayInputStream(image)
val mimeType = attempt(URLConnection.guessContentTypeFromStream(is))
.toEither
.left.map(_ => invalidMimeType(List("Unable to verify mime type of file")))
mimeType match {
case i @ (Right("image/png") | Right("image/jpeg")) => i
case i @ Right("image/gif") if notAnimated(is) => i
case _ => Left(invalidMimeType(List("Uploaded images must be of type png, jpeg, or gif (non-animated)")))
}
}