https://kotlinlang.org logo
Title
v

Vasily Scherbakov

12/10/2021, 8:13 PM
hi guys! can anyone can help me with multipart form data? i have a ktor server endpoint which expects a two parts form data: form item and form data. I can send form item without any problems, but a cant findout a way to send file as PartData.FileItem thx
c

CLOVIS

12/12/2021, 10:17 AM
Are you suck on the server or the client side?
My implementation for the client-side can be found in this package (https://gitlab.com/clovis-ai/formulaide/-/tree/main/client/src/commonMain/kotlin/formulaide.client/files, see also the actuals). It works for JVM and JS, it should be easy to extend to other platforms. I do not know if this is the simplest way or not, but it works well.
a

Aleksei Tirman [JB]

12/13/2021, 8:43 AM
You can find an example for uploading a file with multipart/form-data in the documentation.
c

CLOVIS

12/17/2021, 1:14 PM
@Aleksei Tirman [JB] that example is JVM-only (java.io.File)
a

Aleksei Tirman [JB]

12/17/2021, 1:18 PM
I suppose the part with reading bytes from a file is easily replaceable.