You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/r2/examples/aws/boto3.mdx
+98-55Lines changed: 98 additions & 55 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,95 +9,140 @@ import { Render } from "~/components";
9
9
<Renderfile="keys"product="r2" />
10
10
<br />
11
11
12
-
You must configure [`boto3`](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html) to use a preconstructed `endpoint_url` value. This can be done through any `boto3` usage that accepts connection arguments; for example:
12
+
Configure [`boto3`](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html) to use your R2 endpoint:
You may, however, omit the `aws_access_key_id` and `aws_secret_access_key` arguments and allow `boto3` to rely on the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`[environment variables](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#using-environment-variables) instead.
26
+
You can omit `aws_access_key_id` and `aws_secret_access_key` if you set the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`[environment variables](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html#using-environment-variables).
For large objects (multi-GB files such as training data or video), `upload_fileobj` can become a throughput bottleneck. Its internal thread pool is limited by Python's [GIL](https://en.wikipedia.org/wiki/Global_interpreter_lock), and increasing `max_concurrency` via `TransferConfig` gives diminishing returns beyond ~10 threads.
54
47
55
-
You can also generate presigned links that can be used to share public read or write access to a bucket temporarily.
48
+
Use the low-level multipart API with `ThreadPoolExecutor` instead:
You can use the link generated by the `put_object` example to upload to the specified bucket and key, until the presigned link expires. When using a presigned URL with `ContentType`, the client must include a matching `Content-Type` header in the request.
145
+
Upload using the presigned PUT URL. When using a presigned URL with `ContentType`, the client must include a matching `Content-Type` header:
101
146
102
147
```sh
103
148
curl -X PUT "https://<ACCOUNT_ID>.r2.cloudflarestorage.com/my-bucket/dog.png?X-Amz-Algorithm=..." \
@@ -128,16 +173,14 @@ When generating presigned URLs for uploads, you can limit abuse and misuse by:
128
173
Then generate a presigned URL with a Content-Type restriction:
129
174
130
175
```python
131
-
# Generate a presigned URL with Content-Type restriction
132
-
# The upload will only succeed if the client sends Content-Type: image/png
0 commit comments