Content-Length is not set when using MultiPartFormDataContent
See original GitHub issueKtor Version - 1.1.1 Ktor Engine Used(client or server and name) - Client - okhttp JVM Version - 1.8.0 Operating System - Android Request: PUT content-type: Multipart/form-data Ktor Client Engine: Okhttp & Android
As with the title, the Content-Length
is not set when using MultiPartFormDataContent
. We get transfer-encoding: chunked
instead. It is important to upload files to Django/WSGI powered backends as it is rather difficult about handling file uploads without Content-Length and other http clients such as Retrofit doesn’t have this problem because it added the content-length in multipart/form-data
uploads
GlobalScope.launch(Dispatchers.Main) {
try {
client.submitForm {
url("http://192.168.1.47:8000/api/images/")
method = HttpMethod.Put
header(HttpHeaders.Authorization, "JWT $token")
body = MultiPartFormDataContent(
formData {
append(
"image",
data,
Headers.build {
append(HttpHeaders.ContentType, "image/jpg")
append(HttpHeaders.ContentDisposition, " filename=hello.jpg")
}
)
}
)
}
} catch (e: Exception){
Log.d(this@MainActivity::class.java.simpleName, e.message)
}
}
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:11 (2 by maintainers)
Top Results From Across the Web
c# - MultipartFormDataContent not adding Content-Type in ...
I have a simple HttpClient that does a multipart/form-data post to an endpoint. using ...
Read more >Multipart Form Post in C# - Brian Grinstead
I first tried using the WebClient UploadFile method, but it didn't fit my needs because I wanted to upload form values (id, filename,...
Read more >How do I send a POST request with Content-Length Header?
The data length must be specified in bytes. In this POST request with a Content-Length Header Example, we make a POST request to...
Read more >C# - How to send a file with HttpClient - MAKOLYTE
Shows how to send a file in a multipart/form-data request using HttpClient by loading it into a MultipartFormDataContent object.
Read more >[C#] Upload pictures with HttpClient - data not sending correctly
I'm trying to upload a JPG picture on my server (typical url : http://www.domain.com/upload/{idUser}) and to do that I have been using ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I am encountering this issue as well. The header of the multipart form request has
transfer-encoding: chunked
instead ofContent-Length
which the server requires.Has anyone looked into this issue yet?
I’ve this same problem in version 1.4.2, using android ktor in KMM How can I solve?
Log