【记一下】亚马逊s3接口签名算法中编码uri代码

com.amazonaws.services.s3.internal.S3Signer#sign(Request<?> request, AWSCredentials credentials)计算签名方法中,先对资源URI进行编码,调用了ServiceUtils.urlEncode(resourcePath)方法。方法如下:

/**
 * URL encodes the specified string and returns it.  All keys specified by
 * users need to URL encoded.  The URL encoded key needs to be used in the
 * string to sign (canonical resource path).
 *
 * @param s
 *            The string to URL encode.
 *
 * @return The new, URL encoded, string.
 */
public static String urlEncode(String s) {
    if (s == null) return null;

    try {
        String encodedString = URLEncoder.encode(s, Constants.DEFAULT_ENCODING);
        // Web browsers do not always handle '+' characters well, use the
        // well-supported '%20' instead.
        encodedString =  encodedString.replaceAll("\\+", "%20");
        // Change all "%2F" back to "/", so that when users download a file in a virtual folder by the presigned URL,
        // the web browsers won't mess up the filename. (e.g. 'folder1_folder2_filename' instead of 'filename')
        encodedString = encodedString.replace("%2F", "/");
        encodedString = encodedString.replace("%7E", "~");
        return encodedString;
    } catch (UnsupportedEncodingException e) {
        throw new AmazonClientException("Unable to encode path: " + s, e);
    }
}

aws-java-sdk-1.4.7

转载于:https://my.oschina.net/u/1030459/blog/1502810

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值