Skip to main content

Images

Singularity provides an automated way to process uploaded images in multiple resolutions. The ImageStore provides these capabilities out-of-the-box.

Configuration

PropertyTypeDescriptionDefault Value
singularity.file.storage.image.store-originalBooleanShould the original image be stored alongside the compressed versions?true
singularity.file.storage.s3.smallIntThe width the small image should have at least in pixels.400
singularity.file.storage.s3.mediumIntThe width the medium image should have at least in pixels.800
singularity.file.storage.s3.largeIntThe width the large image should have at least in pixels.1920

Example application.yaml

singularity:
file:
storage:
image:
store-original: true
small: 400
medium: 800
large: 1920

Usage

File Size

You can only upload files smaller than the configured maximum size.

@Service
class MyImageService(
private val imageStore: ImageStore // Inject the FileStorage interface
) {
suspend fun uploadImage(
authentication: AuthenticationOutcome.Authenticated,
file: StreamedFile,
key: String,
isPublic: Boolean
): Result<FileMetadataDocument, FileException> {
// Upload the file and get its metadata
imageStore.upload(
// the metadata key
key = key,
// the file part containing the original image
file = file,
// the authentication outcome for an authenticated principal
authentication = authentication,
isPublic = true
)
}
}

The resized and compressed images will be stored as renditions inside the file metadata.