文档中心 > 对象存储 OSS

OSS如何通过sdk获取object的签名URL

更新时间: 访问次数:1998

 

1)Java SDK:

   Date expiration = new Date(new Date().getTime() + 3600 1000);// 生成URL
   URL url = client.generatePresignedUrl(bucketName, key, expiration);

2)PHP SDK:

    $signedUrl = $ossClient->signUrl($bucket, $object, $timeout);

3)Python SDK:在URL中实现签名,必须至少包含Signature,Expires,OSSAccessKeyId三个参数

     h = hmac.new("OtxrzxIsfpFjA7SwPzILwy8Bw21TLhquhboDYROV",

             "GET\n\n\n1141889120\n/oss-example/oss-api.pdf",

             sha)

     urllib.quote_plus (base64.encodestring(h.digest()).strip())

 

或者

   auth = oss2.Auth(‘您的AccessKeyId’, ‘您的AccessKeySecret’)
   bucket = oss2.Bucket(auth, ‘您的Endpoint’, ‘您的Bucket名’)
   print(bucket.sign_url(‘GET’, ‘object-in-bucket.txt’, 60))

4)Android SDK:

    String url = oss.presignConstrainedObjectURL("<bucketName>", "<objectKey>", 30 60);

5)iOS SDK:

    NSString constrainURL = nil;// sign constrain url

    OSSTask task = [client presignConstrainURLWithBucketName:@"<bucket name>"

                                            withObjectKey:@"<object key>"

                                   withExpirationInterval: 30 * 60];

     if (!task.error) {

          constrainURL = task.result;


       } else {    

           NSLog(@"error: %@", task.error);

       }

6)osscmd:

signurl(sign) oss://bucket/object —timeout=[timeout_seconds]

SDK的具体代码可以参考如下链接:http://docs.aliyun.com/?spm=5176.383338.201.62.MwuAaz#/oss/sdk/java-sdk&preface

 

如果问题还未能解决,请联系售后技术支持


 

FAQ

关于此文档暂时还没有FAQ
返回
顶部