1
我試着從Android文件流式傳輸到一個asp.net服務:流從Android文件到.NET HTTP服務
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();
}
}
,並收到類似這樣的
String base64 = Request.Form["fileBase64"];
byte[] bytes = System.Convert.FromBase64String(base64);
我使用HttpURLConnection的我沒有得到任何例外,但收到的文件(圖像)在這個過程中被破壞。 我嘗試了很多不同的流包裝對,但沒有運氣。任何人都有這方面的經驗? 我流其他形式的條目在同一個連接,這些到達未損壞,例如
&UserID=12345
Gratefull對您有所幫助。
乾杯!