in api/src/main/scala/com/gu/core/store/store.scala [172:207]
def userUpload(
user: User,
file: Array[Byte],
mimeType: String,
originalFilename: String,
isSocial: Boolean = false
): Either[Error, CreatedAvatar] = {
val avatarId = UUID.randomUUID
val now = DateTime.now(DateTimeZone.UTC)
val location = KVLocationFromID(avatarId.toString)
val status = if (isSocial) Inactive else Pending
val created = for {
secureUrl <- fs.presignedUrl(processedBucket, location)
secureRawUrl <- fs.presignedUrl(rawBucket, location)
avatar <- kvs.put(
dynamoTable,
Avatar(
id = avatarId.toString,
avatarUrl = secureUrl.toString,
userId = user.id.toString,
originalFilename = originalFilename,
rawUrl = secureRawUrl.toString,
status = status,
createdAt = now,
lastModified = now,
isSocial = isSocial,
isActive = false
)
)
_ <- fs.put(incomingBucket, location, file, objectMetadata(avatarId, user, originalFilename, mimeType))
} yield CreatedAvatar(avatar)
logIfError(s"Unable to create Avatar with ID: $avatarId. Avatar may be left in an inconsistent state.", created)
}