aliyun / aliyun-oss-java-sdk

Aliyun OSS SDK for Java
1.22k stars 805 forks source link

使用签名认证的url上传文件时无法传入进度响应监听器 #496

Open comenglish opened 1 year ago

comenglish commented 1 year ago
       参考官方上传文件至oss服务器,获取进度数据:https://help.aliyun.com/zh/oss/developer-reference/progress-bar-6?spm=a2c4g.11186623.0.0.33e4466fcHpAuN
       在有获取文件授权签名写入的情况下,无法传入监听器对象,造成使用签名的地址上传文件无法获取上传进度的问题。
       具体Api如下:           
        ProgressListener progressListener = new PutObjectProgressListenerDemo()
        OSSClient ossClient = (OSSClient) new OSSClientBuilder().build(endpoint, oSSAccessKeyId, accessKeySecret, signature);
        PutObjectResult result = ossClient.putObject(url, fin, f.length(), customHeaders, false, progressListener);
        在这里并不能传入progressListener对象。
        经过,研究可以覆盖实现OSSClient增加
        public PutObjectResult putObject(URL signedUrl, InputStream requestContent, long contentLength,
                                 Map<String, String> requestHeaders, boolean useChunkEncoding, ProgressListener progressListener) throws OSSException, ClientException {
    return objectOperation.putObject(signedUrl, requestContent, contentLength, requestHeaders, useChunkEncoding, progressListener);
}
同时覆盖实现OSSObjectOperation,增加  public PutObjectResult putObject(URL signedUrl, InputStream requestContent, long contentLength,Map<String, String> requestHeaders, boolean useChunkEncoding,ProgressListener progressListener) throws OSSException, ClientException 方法

并在相关逻辑中传入对象,例如: GenericRequest req = new GenericRequest().withProgressListener(progressListener) RequestMessage request = new RequestMessage(req, null, null); 方能实现