通过http将图片bitmap转化为byte[]数组上传到服务器,接收到的图片不完整
private static void uploadData(OutputStream out, final String fileFieldName, final byte[] fileBytes)
throws Exception {
StringBuilder temp = new StringBuilder();
ByteArrayInputStream input = new ByteArrayInputStream(fileBytes);
try {
out.write(res);
byte[] buffer = new byte[1024 * 50];
while (true) {
int count = input.read(buffer);
if (count == -1) {
break;
}
out.write(buffer, 0, count);
}
out.write(("\r\n" + END_MP_BOUNDARY).getBytes("UTF-8"));
} catch (IOException e) {
e.printStackTrace();
throw e;
} finally {
if (null != input) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
这是怎么回事,是因为byte[]数组在网络传输过程中丢失了一部分吗?我是用移动4g网络进行的,用wifi上传就没有问题。请教各位大神:这种情况是不是应该加个byte数组校验,一般加什么校验比较有效???