generated from br3ndonland/template-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PUT uploads to object storage client (#25)
Dotenv files are commonly kept in cloud object storage. fastenv provides an object storage client for downloading and uploading dotenv files. S3-compatible object storage allows uploads with either `POST` or `PUT`. This commit will implement uploads with `PUT`. The new `method` argument to `fastenv.ObjectStorageClient.upload()` will accept either `POST` or `PUT`. `POST` was previously the default. #8 `PUT` will now be the default. `PUT` uploads are more widely-supported and standardized. Backblaze B2 does not currently support single-part uploads with `POST` to their S3 API (the B2 native API must be used instead), and Cloudflare R2 does not support uploads with `POST` at all. https://www.backblaze.com/apidocs/b2-upload-file https://developers.cloudflare.com/r2/api/s3/presigned-urls/#supported-http-methods Files will be opened in binary mode and attached with the `content` argument (`httpx_client.put(content=content)`) as suggested in the HTTPX docs (https://www.python-httpx.org/compatibility/). Unlike downloads with `GET`, presigned `PUT` URL query parameters do not necessarily contain all the required information. Additional information may need to be supplied in request headers. In addition to supplying header keys and values with HTTP requests, header keys will be signed into the URL in the `X-Amz-SignedHeaders` query string parameter (alphabetically-sorted, semicolon-separated, lowercased). https://docs.aws.amazon.com/IAM/latest/UserGuide/create-signed-request.html These request headers can specify: - Object encryption. Encryption information can be specified with headers including `X-Amz-Server-Side-Encryption`. Note that, although similar headers like `X-Amz-Algorithm` are included as query string parameters in presigned URLs, `X-Amz-Server-Side-Encryption` is not. If `X-Amz-Server-Side-Encryption` is included in query string parameters, it may be silently ignored by the object storage platform. AWS S3 and Cloudflare R2 now automatically encrypt all objects, but Backblaze B2 will only automatically encrypt objects if the bucket has default encryption enabled. https://docs.aws.amazon.com/AmazonS3/latest/userguide/default-encryption-faq.html https://docs.aws.amazon.com/AmazonS3/latest/userguide/serv-side-encryption.html https://www.backblaze.com/docs/cloud-storage-server-side-encryption https://docs.aws.amazon.com/AmazonS3/latest/userguide/default-encryption-faq.html - Object integrity checks. The `Content-MD5` header defined by RFC 1864 can supply a base64-encoded MD5 checksum. After upload, the object storage platform server will calculate a checksum for the object in the same manner. If the client and server checksums are the same, all expected information was successfully sent to the server. If the checksums are different, this may mean that object information was lost in transit, and an error will be reported. Note that, although Backblaze B2 accepts and processes the `Content-MD5` header, it will report a SHA1 checksum to align with uploads to the B2-native API. https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html https://www.backblaze.com/docs/en/cloud-storage-file-information - Object metadata. Headers like `Content-Disposition`, `Content-Length`, and `Content-Type` can be supplied in request headers. https://docs.aws.amazon.com/AmazonS3/latest/userguide/UsingMetadata.html
- Loading branch information
1 parent
8492656
commit 6968353
Showing
3 changed files
with
145 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.