Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot generate cUrlString() with .httpUpload() #940

Open
vojkny opened this issue Aug 15, 2024 · 0 comments
Open

Cannot generate cUrlString() with .httpUpload() #940

vojkny opened this issue Aug 15, 2024 · 0 comments

Comments

@vojkny
Copy link

vojkny commented Aug 15, 2024

        val logoBytes: ByteArray = /** file to upload */
        val body = listOf(
            "Title" to name,
        )
        return "https://url-to-upload"
            .httpUpload(body)
            // TODO the InlineDataPart should better accept ByteArray instead of String
            .add(InlineDataPart(String(logoBytes), "Logo"))
            .cUrlString()

will fail with

 The inputs have already been written to an output stream and can not be consumed again.
	at com.github.kittinunf.fuel.core.requests.UploadBody.writeTo(UploadBody.kt:100)
	at com.github.kittinunf.fuel.core.requests.UploadBody.toByteArray(UploadBody.kt:76)
	at com.github.kittinunf.fuel.core.requests.RepeatableBody.toByteArray(RepeatableBody.kt:42)
	at com.github.kittinunf.fuel.core.extensions.FormattingKt.cUrlString(Formatting.kt:48)

Which is caused in:

fun Request.cUrlString(): String = buildString {
    …

    // body
    body(body.asRepeatable())
    val escapedBody = String(body.toByteArray()).replace("\"", "\\\"") <--- FAILS HERE on body.toByteArray()
  1. The InlineDataPart provides bytearray, so it is readable again
  2. For input streams, it could just show [input-stream-data] instead of such error

Also notice above, it would be better if InlineDataPart accepted ByteArray

@vojkny vojkny changed the title Cannot generate curl with .httpUpload() Cannot generate cUrlString() with .httpUpload() Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant