Hey everyone, I’ve been trying to upload a simple ...
# android
s
Hey everyone, I’ve been trying to upload a simple pdf or jpeg image via
ktor
client but getting
422 Unprocessable Entity
also debugged a code with backend guy he said the request isn’t perfect
Copy code
suspend fun uploadFile(file: File, mimeType: String) = <http://client.post|client.post>(buildUrl(UPLOAD_FILE)) {
        setBody(
            MultiPartFormDataContent(
                formData {
                    append("file", file.readBytes(), 
                        Headers.build { 
                            append(HttpHeaders.ContentType, mimeType) 
                            append(HttpHeaders.ContentDisposition, "form-data; name=\"file\"; filename=\"${file.name}\"")
                        }
                    )
                }, boundary = "WebAppBoundary"
            )
        )
} here is the code which am trying to upload a file
the api is working fine on postman/swagger
c
#C0A974TJ9 😉
with backend guy he said the request isn’t perfect
so he should tell you whats wrong 😅
s
the issue has been resolved. append(HttpHeaders.ContentDisposition, “form-data; name=\“file\“; filename=\“${file.name}\“”) this line has some issues so I resolved by replacing
Copy code
headersOf(
    HttpHeaders.ContentDisposition, "filename=${file.name}"
)
🙂