直接上代码了。
MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE) {
@Override
public void writeTo(OutputStream outstream) throws IOException {
super.writeTo(new FilterOutputStream(outstream) {
@Override
public void write(@NonNull byte[] buffer, int offset, int length) throws IOException {
super.write(buffer, offset, length);
}
});
}
};
这个是上传的进度监听。注意要使用FilterOutputStream
long total = response.getEntity().getContentLength();
float current = 0;
while ((read_byte = file_in_stream.read(tmp_buffer)) > 0) {
file_out_stream.write(tmp_buffer, 0, read_byte);
if (total > 0) {
current += read_byte;
}
}
网友评论