Skip to content

SudoSOS Back-end API / helpers / validateImageUpload

Function: validateImageUpload() ​

ts
function validateImageUpload(uploadedFile, imageType): Promise<Either<ValidationError, UploadedFile>>;

Validate an uploaded image against the requirements of the given image type.

Format, resolution and aspect ratio are read from the file contents, never from the uploaded file name or mimetype. Dimensions are taken after applying the EXIF orientation, so they match how the image is displayed.

On success, returns a copy of the upload whose name is <imageType><extension>, where the extension is derived from the detected format. Pass that copy to storage so the stored file never inherits the extension of the client-supplied file name.

Parameters ​

ParameterType
uploadedFileUploadedFile
imageTypeImageType

Returns ​

Promise<Either<ValidationError, UploadedFile>>