|
| 1 | +# Copyright 2026 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +"""Common constants and utilities for Resumable Media.""" |
| 16 | + |
| 17 | +# The default size for individual upload chunks (10 MB). |
| 18 | +# When a resumable upload is chunked, the size of each chunk (except the last) |
| 19 | +# must be a multiple of the chunk granularity specified by the server in the |
| 20 | +# `X-Goog-Upload-Chunk-Granularity` header during the initial `start` request. |
| 21 | +# 10 MB is used as a default. |
| 22 | +DEFAULT_CHUNK_SIZE = 10 * 1024 * 1024 # 10MB |
| 23 | + |
| 24 | +# The header specifying the upload protocol. |
| 25 | +# Sent by the client during upload initiation. |
| 26 | +UPLOAD_PROTOCOL_HEADER = "X-Goog-Upload-Protocol" |
| 27 | + |
| 28 | +# The header specifying the protocol command. |
| 29 | +# Sent by the client on active requests (e.g. start, upload, finalize, query). |
| 30 | +UPLOAD_COMMAND_HEADER = "X-Goog-Upload-Command" |
| 31 | + |
| 32 | +# The header specifying the status of the upload. |
| 33 | +# Received from the server. |
| 34 | +UPLOAD_STATUS_HEADER = "X-Goog-Upload-Status" |
| 35 | + |
| 36 | +# The header providing the dedicated upload URL. |
| 37 | +# Received from the server in the start command response. |
| 38 | +UPLOAD_URL_HEADER = "X-Goog-Upload-URL" |
| 39 | + |
| 40 | +# The header specifying the byte offset of the current chunk. |
| 41 | +# Sent by the client during chunk uploads. |
| 42 | +UPLOAD_OFFSET_HEADER = "X-Goog-Upload-Offset" |
| 43 | + |
| 44 | +# The header specifying the number of bytes successfully persisted so far. |
| 45 | +# Received from the server, typically in query responses. |
| 46 | +UPLOAD_SIZE_RECEIVED_HEADER = "X-Goog-Upload-Size-Received" |
| 47 | + |
| 48 | +# The header specifying the required block alignment size for chunks. |
| 49 | +# Received from the server in the start command response. |
| 50 | +UPLOAD_CHUNK_GRANULARITY_HEADER = "X-Goog-Upload-Chunk-Granularity" |
| 51 | + |
| 52 | +# The value indicating the resumable upload protocol. |
| 53 | +# Sent by the client in the `UPLOAD_PROTOCOL_HEADER`. |
| 54 | +UPLOAD_PROTOCOL_VALUE = "resumable" |
| 55 | + |
| 56 | +class UploadCommand: |
| 57 | + """HTTP Header values for the Resumable Upload command header.""" |
| 58 | + START = "start" |
| 59 | + UPLOAD = "upload" |
| 60 | + FINALIZE = "finalize" |
| 61 | + QUERY = "query" |
| 62 | + CANCEL = "cancel" |
| 63 | + |
| 64 | +class UploadStatus: |
| 65 | + """HTTP Header values for the Resumable Upload status header.""" |
| 66 | + ACTIVE = "active" |
| 67 | + FINAL = "final" |
| 68 | + CANCELLED = "cancelled" |
0 commit comments