Skip to content

Commit

Permalink
Rename presigned_url() to get_presigned_url()
Browse files Browse the repository at this point in the history
  • Loading branch information
balamurugana committed Dec 1, 2020
1 parent 2b97a6e commit bb1f0e9
Show file tree
Hide file tree
Showing 5 changed files with 191 additions and 99 deletions.
88 changes: 73 additions & 15 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ s3Client = Minio(
| [`get_bucket_policy`](#get_bucket_policy) | [`presigned_get_object`](#presigned_get_object) |
| [`set_bucket_policy`](#set_bucket_policy) | [`presigned_put_object`](#presigned_put_object) |
| [`delete_bucket_notification`](#delete_bucket_notification) | [`presigned_post_policy`](#presigned_post_policy) |
| [`get_bucket_notification`](#get_bucket_notification) | |
| [`get_bucket_notification`](#get_bucket_notification) | [`get_presigned_url`](#get_presigned_url) |
| [`set_bucket_notification`](#set_bucket_notification) | |
| [`listen_bucket_notification`](#listen_bucket_notification) | |
| [`delete_bucket_encryption`](#delete_bucket_encryption) | |
Expand Down Expand Up @@ -1365,15 +1365,15 @@ __Return Value__
__Example__

```py
# Get presigned URL string to download 'my-objectname' in
# 'my-bucketname' with default expiry.
url = minio.presigned_get_object("my-bucketname", "my-objectname")
# Get presigned URL string to download 'my-object' in
# 'my-bucket' with default expiry (i.e. 7 days).
url = client.presigned_get_object("my-bucket", "my-object")
print(url)

# Get presigned URL string to download 'my-objectname' in
# 'my-bucketname' with two hours expiry.
url = minio.presigned_get_object(
"my-bucketname", "my-objectname", expires=timedelta(hours=2),
# Get presigned URL string to download 'my-object' in
# 'my-bucket' with two hours expiry.
url = client.presigned_get_object(
"my-bucket", "my-object", expires=timedelta(hours=2),
)
print(url)
```
Expand Down Expand Up @@ -1401,15 +1401,15 @@ __Return Value__
__Example__

```py
# Get presigned URL string to upload data to 'my-objectname' in
# 'my-bucketname' with default expiry.
url = minio.presigned_put_object("my-bucketname", "my-objectname")
# Get presigned URL string to upload data to 'my-object' in
# 'my-bucket' with default expiry (i.e. 7 days).
url = client.presigned_put_object("my-bucket", "my-object")
print(url)

# Get presigned URL string to upload data to 'my-objectname' in
# 'my-bucketname' with two hours expiry.
url = minio.presigned_put_object(
"my-bucketname", "my-objectname", expires=timedelta(hours=2),
# Get presigned URL string to upload data to 'my-object' in
# 'my-bucket' with two hours expiry.
url = client.presigned_put_object(
"my-bucket", "my-object", expires=timedelta(hours=2),
)
print(url)
```
Expand Down Expand Up @@ -1445,6 +1445,64 @@ policy.add_content_length_range_condition(
form_data = client.presigned_post_policy(policy)
```

### get_presigned_url(method, bucket_name, object_name, expires=timedelta(days=7), response_headers=None, request_date=None, version_id=None, extra_query_params=None)

Get presigned URL of an object for HTTP method, expiry time and custom request parameters.

__Parameters__
| Param | Type | Description |
|:---------------------|:---------------------|:---------------------------------------------------------------------------------------------------------------------|
| `method` | _str_ | HTTP method. |
| `bucket_name` | _str_ | Name of the bucket. |
| `object_name` | _str_ | Object name in the bucket. |
| `expires` | _datetime.timedelta_ | Expiry in seconds; defaults to 7 days. |
| `response_headers` | _dict_ | Optional response_headers argument to specify response fields like date, size, type of file, data about server, etc. |
| `request_date` | _datetime.datetime_ | Optional request_date argument to specify a different request date. Default is current date. |
| `version_id` | _str_ | Version ID of the object. |
| `extra_query_params` | _dict_ | Extra query parameters for advanced usage. |

__Return Value__

| Return |
|:-----------|
| URL string |

__Example__

```py
# Get presigned URL string to delete 'my-object' in
# 'my-bucket' with one day expiry.
url = client.get_presigned_url(
"DELETE",
"my-bucket",
"my-object",
expires=timedelta(days=1),
)
print(url)

# Get presigned URL string to upload 'my-object' in
# 'my-bucket' with response-content-type as application/json
# and one day expiry.
url = client.get_presigned_url(
"PUT",
"my-bucket",
"my-object",
expires=timedelta(days=1),
response_headers={"response-content-type": "application/json"},
)
print(url)

# Get presigned URL string to download 'my-object' in
# 'my-bucket' with two hours expiry.
url = client.get_presigned_url(
"GET",
"my-bucket",
"my-object",
expires=timedelta(hours=2),
)
print(url)
```

## 5. Explore Further

- [MinIO Golang Client SDK Quickstart Guide](https://docs.min.io/docs/golang-client-quickstart-guide)
Expand Down
57 changes: 57 additions & 0 deletions examples/get_presigned_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
# MinIO Python Library for Amazon S3 Compatible Cloud Storage,
# (C) 2020 MinIO, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import timedelta

from minio import Minio

client = Minio(
"s3.amazonaws.com",
access_key="YOUR-ACCESSKEYID",
secret_key="YOUR-SECRETACCESSKEY",
)

# Get presigned URL string to delete 'my-object' in
# 'my-bucket' with one day expiry.
url = client.get_presigned_url(
"DELETE",
"my-bucket",
"my-object",
expires=timedelta(days=1),
)
print(url)

# Get presigned URL string to upload 'my-object' in
# 'my-bucket' with response-content-type as application/json
# and one day expiry.
url = client.get_presigned_url(
"PUT",
"my-bucket",
"my-object",
expires=timedelta(days=1),
response_headers={"response-content-type": "application/json"},
)
print(url)

# Get presigned URL string to download 'my-object' in
# 'my-bucket' with two hours expiry.
url = client.get_presigned_url(
"GET",
"my-bucket",
"my-object",
expires=timedelta(hours=2),
)
print(url)
30 changes: 17 additions & 13 deletions examples/presigned_get_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname
# are dummy values, please replace them with original values.
from datetime import timedelta

from minio import Minio
from minio.error import ResponseError

client = Minio('s3.amazonaws.com',
access_key='YOUR-ACCESSKEYID',
secret_key='YOUR-SECRETACCESSKEY')
client = Minio(
"s3.amazonaws.com",
access_key="YOUR-ACCESSKEYID",
secret_key="YOUR-SECRETACCESSKEY",
)

# presigned get object URL for object name, expires in 7 days.
try:
print(client.presigned_get_object('my-bucketname', 'my-objectname'))
# Response error is still possible since internally presigned does get
# bucket location.
except ResponseError as err:
print(err)
# Get presigned URL string to download 'my-object' in
# 'my-bucket' with default expiry (i.e. 7 days).
url = client.presigned_get_object("my-bucket", "my-object")
print(url)

# Get presigned URL string to download 'my-object' in
# 'my-bucket' with two hours expiry.
url = client.presigned_get_object(
"my-bucket", "my-object", expires=timedelta(hours=2),
)
print(url)
34 changes: 17 additions & 17 deletions examples/presigned_put_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Note: YOUR-ACCESSKEYID, YOUR-SECRETACCESSKEY, my-bucketname and my-objectname
# are dummy values, please replace them with original values.

import datetime
from datetime import timedelta

from minio import Minio
from minio.error import ResponseError

client = Minio('s3.amazonaws.com',
access_key='YOUR-ACCESSKEYID',
secret_key='YOUR-SECRETACCESSKEY')
client = Minio(
"s3.amazonaws.com",
access_key="YOUR-ACCESSKEYID",
secret_key="YOUR-SECRETACCESSKEY",
)

# Get presigned URL string to upload data to 'my-object' in
# 'my-bucket' with default expiry (i.e. 7 days).
url = client.presigned_put_object("my-bucket", "my-object")
print(url)

# presigned Put object URL for an object name, expires in 3 days.
try:
print(client.presigned_put_object('my-bucketname',
'my-objectname',
datetime.timedelta(days=3)))
# Response error is still possible since internally presigned does get
# bucket location.
except ResponseError as err:
print(err)
# Get presigned URL string to upload data to 'my-object' in
# 'my-bucket' with two hours expiry.
url = client.presigned_put_object(
"my-bucket", "my-object", expires=timedelta(hours=2),
)
print(url)
81 changes: 27 additions & 54 deletions minio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1600,14 +1600,10 @@ def remove_objects(self, bucket_name, delete_object_list,
if error.code != "NoSuchVersion":
yield error

def presigned_url(self, method,
bucket_name,
object_name,
expires=timedelta(days=7),
response_headers=None,
request_date=None,
version_id=None,
extra_query_params=None):
def get_presigned_url(self, method, bucket_name, object_name,
expires=timedelta(days=7), response_headers=None,
request_date=None, version_id=None,
extra_query_params=None):
"""
Get presigned URL of an object for HTTP method, expiry time and custom
request parameters.
Expand All @@ -1627,35 +1623,13 @@ def presigned_url(self, method,
:return: URL string.
Example::
# Get presigned URL string to delete 'my-objectname' in
# 'my-bucketname' with one day expiry.
url = minio.presigned_url(
# Get presigned URL string to delete 'my-object' in
# 'my-bucket' with one day expiry.
url = client.get_presigned_url(
"DELETE",
"my-bucketname",
"my-objectname",
expires=timedelta(days=1),
)
print(url)
# Get presigned URL string to upload 'my-objectname' in
# 'my-bucketname' with response-content-type as application/json
# and one day expiry.
url = minio.presigned_url(
"PUT",
"my-bucketname",
"my-objectname",
"my-bucket",
"my-object",
expires=timedelta(days=1),
response_headers={"response-content-type": "application/json"},
)
print(url)
# Get presigned URL string to download 'my-objectname' in
# 'my-bucketname' with two hours expiry.
url = minio.presigned_url(
"GET",
"my-bucketname",
"my-objectname",
expires=timedelta(hours=2),
)
print(url)
"""
Expand Down Expand Up @@ -1714,19 +1688,19 @@ def presigned_get_object(self, bucket_name, object_name,
:return: URL string.
Example::
# Get presigned URL string to download 'my-objectname' in
# 'my-bucketname' with default expiry.
url = minio.presigned_get_object("my-bucketname", "my-objectname")
# Get presigned URL string to download 'my-object' in
# 'my-bucket' with default expiry (i.e. 7 days).
url = client.presigned_get_object("my-bucket", "my-object")
print(url)
# Get presigned URL string to download 'my-objectname' in
# 'my-bucketname' with two hours expiry.
url = minio.presigned_get_object(
"my-bucketname", "my-objectname", expires=timedelta(hours=2),
# Get presigned URL string to download 'my-object' in
# 'my-bucket' with two hours expiry.
url = client.presigned_get_object(
"my-bucket", "my-object", expires=timedelta(hours=2),
)
print(url)
"""
return self.presigned_url(
return self.get_presigned_url(
"GET",
bucket_name,
object_name,
Expand All @@ -1749,22 +1723,21 @@ def presigned_put_object(self, bucket_name, object_name,
:return: URL string.
Example::
# Get presigned URL string to upload data to 'my-objectname' in
# 'my-bucketname' with default expiry.
url = minio.presigned_put_object("my-bucketname", "my-objectname")
# Get presigned URL string to upload data to 'my-object' in
# 'my-bucket' with default expiry (i.e. 7 days).
url = client.presigned_put_object("my-bucket", "my-object")
print(url)
# Get presigned URL string to upload data to 'my-objectname' in
# 'my-bucketname' with two hours expiry.
url = minio.presigned_put_object(
"my-bucketname", "my-objectname", expires=timedelta(hours=2),
# Get presigned URL string to upload data to 'my-object' in
# 'my-bucket' with two hours expiry.
url = client.presigned_put_object(
"my-bucket", "my-object", expires=timedelta(hours=2),
)
print(url)
"""
return self.presigned_url('PUT',
bucket_name,
object_name,
expires)
return self.get_presigned_url(
"PUT", bucket_name, object_name, expires,
)

def presigned_post_policy(self, policy):
"""
Expand Down

0 comments on commit bb1f0e9

Please sign in to comment.