简体   繁体   中英

Python: How do I generate presigned URLs for IBM Cloud Object Storage?

I followed this information to create HMAC keys for my instance of IBM Cloud Object Storage (COS). I am using the Python SDK for IBM COS . How can I create presigned URIs (links), so that users can upload or download files without authentication?

I am trying to provide the HMAC credentials as part of the client parameters, but I receive errors like the following:

File "/usr/lib/python2.7/site-packages/ibm_botocore/config.py", line 142, in _record_user_provided_options 'Got unexpected keyword argument \\'%s\\'' % key) TypeError: Got unexpected keyword argument 'cos_hmac_keys'

Here is the HMAC keys structure:

"cos_hmac_keys": {
    "access_key_id": "dfe869efasdasd",
    "secret_access_key": "f04e500a66asdasdasd5bfd34c82"
  }

I found out that the COS S3 client is either reading the HMAC credentials from the IBM Cloud config directory or you have to pass them under different name:

cos = ibm_boto3.client('s3', myserviceapikey, endpoint_url=myendpointurl, aws_access_key_id=config["cos_hmac_keys"]["access_key_id"], aws_secret_access_key=config["cos_hmac_keys"]["secret_access_key"])

Basically, I have to map cos_hmac_keys.access_key_id to aws_access_key_id and cos_hmac_keys.secret_access_key to aws_secret_access_key .

With that COS client initialized, then I can create the presigned URI:

theURL=cos.generate_presigned_url('get_object', Params = {'Bucket': mybucket, 'Key': myobject}, ExpiresIn = 600)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM