Hello everyone I’m facing an issue while trying t...
# ktor
r
Hello everyone I’m facing an issue while trying to create file for image to be uploaded on multipart request in ktor , I can’t find file object
a
What do you mean that you can't find a file object?
r
I need to create a file from the image to be able to upload it, when trying to use File(“image”) the File object doesn’t exist
a
Can you share your code?
I suggest checking if the file by the specified path exists relative to the current working directory.
r
val response = client.post("https://httpbin.org/post") { setBody( MultiPartFormDataContent( formData { append("description", "Ktor logo") append("type", "123", Headers.build { append(HttpHeaders.ContentType, "application/json") }) append("image", File("archive.zip").readBytes(), Headers.build { append(HttpHeaders.ContentType, "image/png") append(HttpHeaders.ContentDisposition, "filename=\"ktor_logo.png\"") }) }, boundary = "WebAppBoundary" ) ) }
The error is on compile no on run time
a
Can you share the complete message of the compile-time error?
r
File(“archive.zip”) cannot be resolved
a
What platform do you target? Is it JVM?
r
Expression ‘File’ or type ‘contentDisposition’ can’t be invoked as a function. The function ‘invoke()’ is not found
It’s KMP on the common module
Not JVM
a
The code you referred to is to execute on JVM. You can read my answer on uploading a file in the common source set. It's similar to sending the multipart content.
r
Thank you very much