https://kotlinlang.org logo
j

Jamy

02/23/2021, 3:12 AM
Hello, I tried to make a multipart request with an
Upload
form control but when I want to get my file from my form, It always return null on
upload
field even if I used your sample on your doc: Client side file handling
Copy code
val pictureForm = formPanel<Request> {
    add(Request::upload,
        Upload(multiple = false, label = "Upload files (images only)").apply {
            showUpload = false
            showCancel = false
            explorerTheme = true
            dropZoneEnabled = true
            allowedFileTypes = setOf("image")
        })
}
button("Submit").onClick {
    GlobalScope.launch {
        val fdata = pictureForm.getDataWithFileContent()
        val firstImage = fdata.upload?.firstOrNull()?.content
        if (firstImage != null) {
            Alert.show("Image", "<img src=\"$firstImage\">", rich = true)
        }
        console.log(firstImage)
    }
}
r

Robert Jaros

02/23/2021, 7:58 AM
You need to set
uploadUrl
parameter
The documentation uses
/
value
It's important, because if you omit this parameter, the component works in standard form submission mode (https://kvision.gitbook.io/kvision-guide/part-2-advanced-features/form-controls-guide#standard-html-form-submission).
If the parameter is set you can use two other modes.
I've added a note in the documetation.
j

Jamy

02/23/2021, 8:16 AM
Ahh sorry I bad, I didn't see your note 😶 Thank you !
Did you just add the note ? Or was it there before ?
r

Robert Jaros

02/23/2021, 9:15 AM
I've added the note just now.
The example code has "/" parameter, but it wasn't clear enough.