I have built an app with a Spring Boot Gradle Kotlin Backend, that can store and upload Multipart files to a Postgres database. The data is stored in a ByteArray. So far everything is working fine.
Now I want to add an Image URL to make it available in my JSON Object to later grab it and display it on my client side like the ones on Unsplash.
imageURL
"imageURL": "https://xyz.jpg"
File model
@Entity
@Table(name = "file")
data class File(
@Id
val id: UUID = UUID.randomUUID(),
val createdAt: LocalDateTime = LocalDateTime.now(),
var updatedAt: LocalDateTime = LocalDateTime.now(),
var likes: Int = 0,
var likedByUser: Boolean = false,
var description: String = "",
val downloadLink: URI = URI("https://unsplasy-backend.herokuapp.com/files/download/$id"),
var name: String = "",
var type: String = "",
@Basic(fetch = FetchType.LAZY)
private val data: ByteArray = byteArrayOf(),
val imageURL: TODO = "TODO"
)
Store
fun store(file: MultipartFile): File {
val fileName = file.originalFilename.toString()
val fileToSave = File(
name = fileName,
type = file.contentType.toString(),
data = file.bytes
)
return fileRepository.save(fileToSave)
}