Add PUT uploads to object storage client #25
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
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
orPUT
. This PR will implement uploads withPUT
.Changes
This PR will add a
method
argument tofastenv.ObjectStorageClient.upload()
that accepts eitherPOST
orPUT
.POST
was previously the default, butPUT
will now be the default becausePUT
uploads are more widely-supported and standardized. Backblaze B2 does not currently support single-part uploads withPOST
to their S3 API (the B2 native API must be used instead), and Cloudflare R2 does not support uploads withPOST
at all.Files will be opened in binary mode and attached with the
content
argument (httpx_client.put(content=content)
) as suggested in the HTTPX docs.Unlike downloads with
GET
, presignedPUT
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 should be signed into the URL in theX-Amz-SignedHeaders
query string parameter (alphabetically-sorted, semicolon-separated, lowercased).These request headers can specify:
X-Amz-Server-Side-Encryption
. Note that, although similar headers likeX-Amz-Algorithm
are included as query string parameters in presigned URLs,X-Amz-Server-Side-Encryption
is not. IfX-Amz-Server-Side-Encryption
is included in query string parameters, it may be silently ignored by the object storage platform. AWS S3 now automatically encrypts all objects and Cloudflare R2 does also, but Backblaze B2 will only automatically encrypt objects if the bucket has default encryption enabled.Content-MD5
header, defined by RFC 1864, can supply a base64-encoded MD5 checksum. After the upload is completed, 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, this means that 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 theContent-MD5
header, it will report a SHA1 checksum to align with uploads to the B2-native API.Content-Disposition
,Content-Length
, andContent-Type
can be supplied in request headers.Related