zeeshanejaz / unirest-android

This is an android port of unirest-java
MIT License
32 stars 13 forks source link

Cannot upload image as byte array #6

Closed clfristoe closed 6 years ago

clfristoe commented 6 years ago

Is there a way to add a body with a byte array to an HttpRequestWithBody? I am trying to upload images to a server.

zeeshanejaz commented 6 years ago

Try APIMATIC. It will generate the right code for you.

clfristoe commented 6 years ago

Can you be a little bit more specific? The api I am making the call to only accepts byte arrays and right now the request.body() only accepts strings. http://d.pr/i/RBU1mj

zeeshanejaz commented 6 years ago

This is a fairly old library. It was made for a code-generator called APIMATIC. The code generator has since moved on to use better approach for file uploading. I think in the long run, it will benefit to use APIMATIC to write the code for you.

But you want to use this library as is, may be have a look at the line 68 of src/main/java/com/mashape/unirest/request/HttpRequestWithBody.java. This method allows you to attach a file directly rather than having to load it into a byte array first.