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

Example of uploading raw binary data file using Ninjato #16

Open
free5ty1e opened this issue Oct 15, 2020 · 2 comments
Open

Example of uploading raw binary data file using Ninjato #16

free5ty1e opened this issue Oct 15, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@free5ty1e
Copy link

free5ty1e commented Oct 15, 2020

Question

I've been working with Ninjato for non-upload calls for a couple weeks now, and it works great! Very flexible and does everything I've needed with intercepting responses and retry logic and everything.

However, I can't seem to figure out how to construct a MultiPartEntity / MultiPart Body like I've used before in Apache's old HTTP libraries and add it to the Ninjato Body object. I see the okhttp MultiPartBody but I'm not sure a) how to use this with Ninjato's Body object, and b) not sure how to addBinaryPart() like I did in Apache (see below method I am looking for in Ninjato)

public MultipartEntityBuilder addBinaryBody(String name, byte[] b, ContentType contentType, String filename) {
        return this.addPart(name, new ByteArrayBody(b, contentType, filename));
    }

Suggestion (Optional)

If this doesn't already exist in the sample app / sample code or docs, can it be added? I must be missing something.

Environment

I am using version 0.3.1 which is indicated to be the latest version both in the README.md and at maven central. I am working in Kotlin wherever possible but I am interfacing with a fair amount of existing Java as well.

@free5ty1e free5ty1e added the question Further information is requested label Oct 15, 2020
@Unlimity
Copy link
Member

Unlimity commented Oct 15, 2020

Hi there!
Unfortunately, multipart form data is not supported out of the box by library at the moment, since this is a rare scenario and no time was put into supporting this feature.
You can construct such body manually, or use OkHttp or Apache directly.
Or you can try and contribute support of multipart body to the library 👍

I would imagine it looking something like this:

post {
    endpointUrl = ""
    body = multipart { // We already have similar extension for formUrlEncoded
        "part1" to "text"
        "part2" to File("/myFile.txt")
    }
}

I will try to implement something like that myself, but the timeline for that is unclear.
Cheers!

@Unlimity Unlimity added enhancement New feature or request and removed question Further information is requested labels Oct 15, 2020
@free5ty1e
Copy link
Author

Thank you so much! I understand now; I thought I was missing part of the library as I was poking through the available methods and classes. If I get something worthy of contribution together, I'll put together a PR. I love the library, thank you once again for Ninjato!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants