I\'m trying to do something I thought would be relatively simple: Upload an image to a server with the Android SDK. I\'m found a lot of example code:
http://groups.g
You can you use GentleRequest, which is lightweight library for making http requests(DISCLAIMER: I am the author):
Connections connections = new HttpConnections();
Binary binary = new PacketsBinary(new
BufferedInputStream(new FileInputStream(file)),
file.length());
//Content-Type is set to multipart/form-data; boundary=
//{generated by multipart object}
MultipartForm multipart = new HttpMultipartForm(
new HttpFormPart("user", "aplication/json",
new JSONObject().toString().getBytes()),
new HttpFormPart("java", "java.png", "image/png",
binary.content()));
Response response = connections.response(new
PostRequest(url, multipart));
if (response.hasSuccessCode()) {
byte[] raw = response.body().value();
String string = response.body().stringValue();
JSONOBject json = response.body().jsonValue();
} else {
}
Feel free to check it out: https://github.com/Iprogrammerr/Gentle-Request