Im trying to stream a file from android to an asp.net service:
private static void writeFile(File file, DataOutputStream out)
throws IOException {
BufferedInputStream bufferedFileIs = null;
Base64OutputStream base64out = null;
try {
out.writeBytes("fileBase64=");
base64out = new Base64OutputStream(out, Base64.DEFAULT);
FileInputStream fileIs = new FileInputStream(file);
bufferedFileIs = new BufferedInputStream(fileIs);
int nextByte;
while ((nextByte = bufferedFileIs.read()) != -1) {
base64out.write(nextByte);
}
} finally {
if (bufferedFileIs != null) {
bufferedFileIs.close();
}
if(base64out != null)
base64out.flush();
}
}
and receive it like this
String base64 = Request.Form["fileBase64"];
byte[] bytes = System.Convert.FromBase64String(base64);
I use an HttpURLConnection and I dont get any exceptions but the received file(image) is corrupted in the process. I tried ALOT of different stream wrapper pairs, but no luck. Anyone have experience in this? I stream other form entries in the same connection and these arrive un-corrupted, for example
&UserID=12345
Gratefull for your help.
Cheers!
Solved it:
Prepare the file:
post the request:
after this the webserver complained:
max request-length defaults to 4mb so i set this in web.config:
Which allows files up to 1GB(!).
edit:
Forgot the server code: