io.appwrite.models.InputFile.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sdk-for-kotlin Show documentation
Show all versions of sdk-for-kotlin Show documentation
Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Kotlin SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)
package io.appwrite.models
import java.io.File
import java.net.URLConnection
import java.nio.file.Files
import java.nio.file.Paths
class InputFile private constructor() {
lateinit var path: String
lateinit var filename: String
lateinit var mimeType: String
lateinit var sourceType: String
lateinit var data: Any
companion object {
fun fromFile(file: File) = InputFile().apply {
path = file.canonicalPath
filename = file.name
mimeType = Files.probeContentType(Paths.get(file.canonicalPath))
?: URLConnection.guessContentTypeFromName(filename)
?: ""
sourceType = "file"
}
fun fromPath(path: String): InputFile = fromFile(File(path)).apply {
sourceType = "path"
}
fun fromBytes(bytes: ByteArray, filename: String = "", mimeType: String = "") = InputFile().apply {
this.filename = filename
this.mimeType = mimeType
data = bytes
sourceType = "bytes"
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy