Closed Jamesgt closed 5 years ago
It's very surprising to see this as missing in such a good API !!!
Please add it as it would be like very handy for uploads!!
Thanks, Krishna
For time being, I've edited the source code of com.mashape.unirest.request.body.MultipartBody and achieved it by adding the below method:
public MultipartBody field(String name, InputStream stream, ContentType contentType, String fileName) { return field(name, new InputStreamBody(stream, contentType, fileName), true, contentType.getMimeType()); }
public HttpEntity getEntity() { if (hasFile) { MultipartEntityBuilder builder = MultipartEntityBuilder.create(); if (mode != null) { builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); } for (String key : keyOrder) { List
Nice, you can help their work by creating a pull request with your changes.
Yes please submit a PR for this. Make sure to include some tests.
I did pull request, can find the status at: https://github.com/Mashape/unirest-java/pull/93
Seeing inconsistent behavior on this pull request. The following works...
final HttpResponse
However, when I change the file
type from File to InputStream:
final HttpResponse
I see errors in the netty web-service stating the file
parameter isn't present...I doesn't seem that the "file" key is getting added to the request.
We do have one like this but it requires a file name.
It would be nice to have also
Then not only files written to disk can be sent, but also ones generated and kept only in memory.