Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
comenglish opened this issue Sep 14, 2023 · 0 comments
Open

Comments

@comenglish
Copy link

       参考官方上传文件至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);
方能实现

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant