3.9.0-rc 3.8.0 (latest) 3.7.0 3.6.0 3.5.0 3.4.0 3.3.0 3.2.0 2.48.0-rc 2.47.1 2.46.0 2.45.0 2.44.0 2.43.0 2.42.0 2.41.0 2.40.0 2.39.0 2.38.0 2.37.0 2.36.0 2.35.0 2.34.0 2.33.0 2.32.0 2.31.0 2.30.0 2.29.0 2.28.0 2.27.0 2.26.0 2.25.1 2.24.0 2.23.0 2.22.1 2.21.0 2.20.0 2.19.0 2.18.0 2.17.0 2.16.0 2.15.1 2.14.0 2.13.0 2.12.0 2.11.0 An interface to asynchronously perform resumable uploads.
The client library uses the `google.storage.v2.StorageService.BidiWriteObject` RPC to perform asynchronous resumable uploads to Google Cloud Storage. As the name implies, this is a bi-directional RPC. The messages sent via this RPC are `google.storage.v2.BidiWriteObjectRequest` and `google.storage.v2.BidiWriteObjectResponse`.

- The `BidiWriteObjectRequest` messages upload the object data.
- The last `BidiWriteObjectRequest` message in an upload must include a `finalize` attribute. These messages result in a `BidiWriteObjectResponse` message, which includes the metadata of the GCS object created by the upload.
- `BidiWriteObjectRequest` messages may include a `flush` attribute. Such messages result in a `BidiReadObjectResponse` message, which includes how much of the uploaded data has been persisted.
- `BidiWriteObjectRequest` messages may not include more than `google.storage.v2.ServiceConstants.MAX_WRITE_CHUNK_BYTES` bytes of payload.

In this interface different member functions write messages with different attributes.

The [`Write()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1ad3886e9ff8442a8ded0933869d1e1cfb) member function uploads some data, without setting any `finalize` or `flush` attributes. If necessary, the data is broken into multiple `BidiWriteObjectRequest` messages.

The [`Finalize()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1a2e371d1542fa1211217bd19397efc7be) member function uploads some data and sets the `finalize` attribute. If needed, the data is broken into multiple messages to satisfy the `MAX_WRITE_CHUNK_BYTES` limit. Only the last message has the `finalize` attribute. This function also waits for the response message and returns the object metadata (or an error).

The [`Flush()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1ae822733a42eacea93a532bb0dc362a3d) member function uploads some data and sets the `flush` attribute. As with the other functions the data may need to be broken into multiple messages. Only the last message will have the `flush` attribute set.

This interface can be used to mock the behavior of these bidirectional streaming RPCs. Applications may use these mocks in their own tests.

> [!WARNING]
> **Warning:** We expect most applications will use this class in mocks or via the [`AsyncWriter`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriter) wrapper, and do not recommend its use outside mocks. If using this class directly keep in mind the following restrictions: - Never destroy an [`AsyncWriterConnection`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection) object while any calls to [`Write()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1ad3886e9ff8442a8ded0933869d1e1cfb), [`Flush()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1ae822733a42eacea93a532bb0dc362a3d), [`Query()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1a7604e26bd037803963873b056410fdbb), or [`Finalize()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1a2e371d1542fa1211217bd19397efc7be) are pending. - Have at most one call to [`Write()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1ad3886e9ff8442a8ded0933869d1e1cfb) or [`Flush()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1ae822733a42eacea93a532bb0dc362a3d) pending. - Do not issue a [`Write()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1ad3886e9ff8442a8ded0933869d1e1cfb) call while a [`Flush()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1ae822733a42eacea93a532bb0dc362a3d) call is pending or vice-versa. - Do not issue any [`Finalize()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1a2e371d1542fa1211217bd19397efc7be) calls while a [`Write()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1ad3886e9ff8442a8ded0933869d1e1cfb), [`Flush()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1ae822733a42eacea93a532bb0dc362a3d), or [`Query()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1a7604e26bd037803963873b056410fdbb) call is pending. - Only issue one [`Finalize()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1a2e371d1542fa1211217bd19397efc7be) call. - Issue exactly one [`Query()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1a7604e26bd037803963873b056410fdbb) call after a [`Flush()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1ae822733a42eacea93a532bb0dc362a3d) call completes.

## Functions

### Cancel()

Cancels the streaming RPC, terminating any pending operations.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `void` |   |

### UploadId() const

Returns the upload id. Used to checkpoint the state and resume uploads.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `std::string` |   |

### PersistedState() const

Returns the last known state of the upload.
Updated during initialization and by successful [`Query()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1a7604e26bd037803963873b056410fdbb) or [`Finalize()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1a2e371d1542fa1211217bd19397efc7be) requests.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `std::variant< std::int64_t, google::storage::v2::Object >` |   |

### Write(WritePayload)

Uploads some data to the service.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `payload` | `WritePayload` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `future< Status >` |   |

### Finalize(WritePayload)

Finalizes an upload.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
|   | `WritePayload` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `future< StatusOr< google::storage::v2::Object > >` |   |

### Flush(WritePayload)

Uploads some data to the service and flushes the value.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `payload` | `WritePayload` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `future< Status >` |   |

### virtual Close(WritePayload)

Cleanly flushes pending data and piggybacks a stream half-close (WritesDone).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `payload` | `WritePayload` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `future< Status >` |   |

### Query()

Wait for the result of a [`Flush()`](https://docs.cloud.google.com/cpp/docs/reference/storage/latest/classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection#classgoogle_1_1cloud_1_1storage_1_1AsyncWriterConnection_1ae822733a42eacea93a532bb0dc362a3d) call.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `future< StatusOr< std::int64_t > >` |   |

### GetRequestMetadata()

Return the request metadata.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `RpcMetadata` |   |

### WriteHandle() const

Returns the latest write handle, if any.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `std::optional< google::storage::v2::BidiWriteHandle >` |   |

### virtual PersistedChecksums() const

Returns the latest persisted data checksums, if any.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `std::optional< google::storage::v2::ObjectChecksums >` |   |