android - Multipart form file send writeFully fails with "java.net.ProtocolException: unexpected end of stream&quot

admin2025-04-28  2

i've sent a file to server using retrofit it was working correctly . i refactored my project to ktor and it keeps getting the: unexpected end of stream exeception.

 httpClient.submitFormWithBinaryData(
            url = ApiConstants.SETTING_POS_PHOTO_UPLOAD,
            formData = formData {
                
                append("serial_number", SK210Manager.getSerialNumber())
                appendInput(
                    "photo", headers = Headers.build {
                        append(HttpHeaders.ContentType, uploadPhotoRequest.contentType)
                        append(
                            HttpHeaders.ContentDisposition,
                            "filename=${TransactionDetails.imageFileName}"
                        )
                    },
                    size = uploadPhotoRequest.file.size.toLong()
                ) {
                    buildPacket {
                        writeFully(uploadPhotoRequest.file)
                    }
                }

            }) {

        }
class UploadPhotoRequest(
val cashlessId = "1111",
val file: ByteArray,
val contentType = "image/jpg",)

i can not find where is the problem

转载请注明原文地址:http://www.anycun.com/QandA/1745854206a91259.html