The question could seems silly but I don't want to do a mistake. As explained in the title, I want to send multiple fields to a WS using post method. To be simple, a title (a string), and an image. So far, I have succedded into sending the image (after A LOT of troubles).
Here is the android code:
String urlServer = GlobalSession.IP + "insert_reportByte";
URL url = new URL(urlServer);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("Content-Type","multipart/form-data");
DataOutputStream outputStream = new DataOutputStream(
connection.getOutputStream());
outputStream.write(outputByteArray, 0, outputByteArray.length);
Log.d("Report", " Amount of data sent for the picture: " + outputByteArray.length);
int serverResponseCode = connection.getResponseCode();
String serverResponseMessage = connection.getResponseMessage();
outputStream.flush();
outputStream.close();
that is sucessfuly sending the picture (outputByteArray) the the following WS:
public void insert_reportByte(Stream input)
{
MyEntities entities = new MyEntities();
byte[] image = new byte[30*1024];
using (MemoryStream ms = new MemoryStream())
{
int read;
while ((read = input.Read(image, 0, image.Length)) > 0)
{
ms.Write(image, 0, read);
}
}
String base64stringimage = System.Convert.ToBase64String(image,0,image.Length);
entities.insert_report("name hard coded", base64stringimage);
}
So, I want to switch from that delcaration to public void insert_reportByte(String name, Stream input)
. How to do so? Or do I have to send everything in the stream an then recovering one by one the parameters transmitted?
Thanks for tips!