我正在尝试使用下面提到的方式在我的 Android 客户端上显示上传进度
MultipartEntity reqEntity = new MultipartEntity(){
@Override
public void writeTo(final OutputStream outstream) throws IOException {
super.writeTo(new UploadOutputStream(outstream,listener));
}
};
public class UploadOutputStream extends FilterOutputStream {
private final ProgressListener listener;
private long transferred;
public UploadOutputStream(final OutputStream out, final ProgressListener listener)
{
super(out);
this.listener = listener;
this.transferred = 0;
}
public void write(byte[] b, int off, int len) throws IOException
{
out.write(b, off, len);
this.transferred += len;
this.listener.transferred(this.transferred);
}
public void write(int b) throws IOException
{
out.write(b);
this.transferred++;
this.listener.transferred(this.transferred);
}
}
我将图像添加到多部分 ByteArrayBody 如下
reqEntity.addPart("image", bab);
问题是我只有在整个图像上传后才能看到进度更新。我想要上传块时的进度。
任何帮助是极大的赞赏
非常感谢
马南