question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multipart not reading all/any parts

See original GitHub issue

Hi, I am trying to upload an image/file…

I ran into a problem that the multiplart.readAllParts() returns everytime empty list, even when I send a file! I migrated from a version 0.3.2 (I think) to 0.9.1… I have read this issue: https://github.com/ktorio/ktor/issues/139 but it seems as no one has answered the question.

I have even tried creating a form with the correct enctype and uploading the file through the form, without any success. I also tried uploading the file through $.ajax() method in jqeury, also without any success.

My code:

if(call.request.isMultipart()) {
                val multipart = call.receiveMultipart()
                println("FILES:" + multipart.readPart())
                multipart.forEachPart { part ->
                    when (part) {
                        is PartData.FileItem -> {
                            files += part
                        }
                    }
                }
            }

I was reading this documentation: http://ktor.io/servers/uploads.html

btw, thank you very much for developing ktor! I am developing my graduation project in it!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:14 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
betterclevercommented, Mar 23, 2018

I am using Ktor version: 0.9.2-alpha-2 with Netty engine. My code looks like:

route("/files") {
                    post("/new") {
                        val multipart = call.receiveMultipart()
                        var title = ""
                        var videoFile: File? = null

                        multipart.forEachPart { part ->
                            when (part) {
                                is PartData.FormItem -> if (part.name == "title") {
                                    title = part.value
                                }
                                is PartData.FileItem -> {
                                    val ext = File(part.originalFileName).extension
                                    val file = File(uploadDir, "upload-${System.currentTimeMillis()}-${"AVX".hashCode()}-${title.hashCode()}.$ext")
                                    part.streamProvider().use { its -> file.outputStream().buffered().use { its.copyTo(it) } }
                                    videoFile = file
                                }
                            }

                            part.dispose()
                        }

                        call.respond("done")
                    }
                }

I tried putting some debugging breakpoints. The call doesn’t seem to enter the forEachPart and server is stuck with no logs whatsoever. I am sending request with Postman and can confirm same multipart request works with my nodejs express server.

I tried running YouKube example. While running example, the browser seems to be stuck here pointing towards this issue only.

screenshot from 2018-03-16 00-08-16

1reaction
monareziocommented, Mar 23, 2018

I reproduced the same bug as @betterclever

Ktor: 0.9.1 Engine: Netty

I guess its because of the readPart() It returns everytime null, I tried looking deeper into the code, but, since I did not design Ktor, it is very hard for me to understand the code 😕.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Not able to read Multipart file using spring controller when file ...
Able to read the file contents successfully in my server class (servlet) using the org.apache.commons.fileupload.servlet.ServletFileUpload APIs.
Read more >
Uploading and copying objects using multipart upload
You can upload these object parts independently and in any order. If transmission of any part fails, you can retransmit that part without...
Read more >
ZArchiver - Apps on Google Play
ZArchiver - is a program for archive management. It has a simple and functional interface. The app doesn't have permission to access the...
Read more >
Jan. 6 panel urges Trump prosecution with criminal referral
The House Jan. 6 committee is urging the Justice Department to bring criminal charges against former President Donald Trump and his allies.
Read more >
Hexis graphics - Centro Didattico Atesino
HEXIS catalogues - Now available as a digital edition for reading and ... FranceHexis Graphics Description HEXIS is not only a self-adhesive film ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found