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

getSymlink对历史版本的支持 #502

Open
shikaiwei1 opened this issue Dec 5, 2023 · 2 comments
Open

getSymlink对历史版本的支持 #502

shikaiwei1 opened this issue Dec 5, 2023 · 2 comments

Comments

@shikaiwei1
Copy link

当前版本中,getSymlink方法即使通过GenericRequest传入versionId参数,在请求时也不会带上该参数。导致无法获取到历史版本的软链接信息;
同时,我这边通过手动拼接参数,调用时带上versionId直接访问API,证实是可以返回正确的历史版本软链接的信息(“x-oss-symlink-target”)。是否可以在SDK中添加相应支持?

@woxinfeixiang233
Copy link

woxinfeixiang233 commented Dec 5, 2023 via email

@shikaiwei1
Copy link
Author

附上手动调用可以正常返回symlink-target信息的代码:

    public static String getSymlinkVersionTarget(
            String bucketName, String symlink, String versionId, String endpoint,
            AliyunAccountConfigEntity accountConfigEntity) throws IOException {
        RequestSigner signer = createSigner(bucketName, symlink, accountConfigEntity);
        RequestMessage requestMessage = new RequestMessage(
                bucketName, symlink
        );
        // Headers
        requestMessage.getHeaders().put(OSSHeaders.DATE, DateUtil.formatRfc822Date(new Date()));
        requestMessage.addParameter(RequestParameters.SUBRESOURCE_VRESION_ID, versionId);
        requestMessage.addParameter(RequestParameters.SUBRESOURCE_SYMLINK, null);
        signer.sign(requestMessage);
        //使用okhttp进行访问
        OkHttpClient client = new OkHttpClient.Builder().build();
        // 创建Request对象
        Request request = new Request.Builder()
                .url(new DefaultUriBuilderFactory().builder()
                        .host(String.format("%s.%s", bucketName, endpoint))
                        .scheme("https")
                        .path(symlink)
                        .queryParam(RequestParameters.SUBRESOURCE_VRESION_ID, versionId)
                        .queryParam(RequestParameters.SUBRESOURCE_SYMLINK, Collections.emptyList())
                        .build().toASCIIString())
                .headers(Headers.of(requestMessage.getHeaders()))
                .build();
        Response response = client.newCall(request).execute();
        return HttpUtil.urlDecode(response.headers().get(OSSHeaders.OSS_HEADER_SYMLINK_TARGET), "UTF-8");
    }

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

2 participants