Mahvi
05/06/2024, 6:48 AMStefan Oltmann
05/06/2024, 7:04 AMMahvi
05/06/2024, 7:51 AMColumn(modifier = Modifier.padding(20.dp)) {
var showFilePicker by remember { mutableStateOf(false) }
Button(onClick = { showFilePicker = true }) {
Text("TEXT")
}
val fileType = listOf("jpg", "png")
FilePicker(
show = showFilePicker,
fileExtensions = fileType
) { platformFile ->
showFilePicker = false
println("platformFile $platformFile")
}
}
Mahvi
05/06/2024, 7:51 AMStefan Oltmann
05/06/2024, 7:51 AMMahvi
05/06/2024, 7:51 AMMahvi
05/06/2024, 7:52 AMStefan Oltmann
05/06/2024, 7:53 AMMahvi
05/06/2024, 7:54 AMMahvi
05/06/2024, 7:54 AMStefan Oltmann
05/06/2024, 7:55 AMStefan Oltmann
05/06/2024, 7:56 AMStefan Oltmann
05/06/2024, 7:56 AMMahvi
05/06/2024, 7:57 AMStefan Oltmann
05/06/2024, 7:59 AMMahvi
05/06/2024, 8:00 AMimport io.ktor.client.request.*
import io.ktor.client.request.forms.*
import io.ktor.client.statement.*
import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.server.application.*
import io.ktor.server.testing.*
import io.ktor.utils.io.streams.*
import org.junit.*
import java.io.*
import kotlin.test.*
import kotlin.test.Test
class ApplicationTest {
@Test
fun testUpload() = testApplication {
val boundary = "WebAppBoundary"
val response = <http://client.post|client.post>("/upload") {
setBody(
MultiPartFormDataContent(
formData {
append("description", "Ktor logo")
append("image", File("ktor_logo.png").readBytes(), Headers.build {
append(HttpHeaders.ContentType, "image/png")
append(HttpHeaders.ContentDisposition, "filename=\"ktor_logo.png\"")
})
},
boundary,
ContentType.MultiPart.FormData.withParameter("boundary", boundary)
)
)
}
assertEquals("Ktor logo is uploaded to 'uploads/ktor_logo.png'", response.bodyAsText())
}
}
Mahvi
05/06/2024, 8:00 AMStefan Oltmann
05/06/2024, 8:01 AM