Open hyhub opened 6 years ago
import com.aliyun.oss.event.ProgressEvent; import com.aliyun.oss.event.ProgressEventType; import com.aliyun.oss.event.ProgressListener;
public class PutObjectProgressListener implements ProgressListener {
@Override
public void progressChanged(ProgressEvent progressEvent) {
switch (progressEvent.getEventType()) {
case TRANSFER_STARTED_EVENT:
System.out.println("Upload started");
break;
case REQUEST_CONTENT_LENGTH_EVENT:
System.out.println("Request content length: " + progressEvent.getBytes());
break;
case RESPONSE_CONTENT_LENGTH_EVENT:
System.out.println("Response content length: " + progressEvent.getBytes());
break;
case TRANSFER_COMPLETED_EVENT:
System.out.println("Upload completed");
break;
case TRANSFER_FAILED_EVENT:
System.out.println("Upload failed");
break;
default:
break;
}
}
}
带进度条的上传,使用FileInputStream,无法执行case RESPONSE_CONTENT_LENGTH_EVENT eg: public static void main(String[] args) {
// // 带进度条的下载 // client.getObject(new GetObjectRequest(bucketName, key). //withProgressListener(new GetObjectProgressListener()), fh);
//
} catch (Exception e) {
e.printStackTrace();
}
}