Class AsyncWriterConnection (2.22.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() member function uploads some data, without setting any finalize or flush attributes. If necessary, the data is broken into multiple BidiWriteObjectRequest messages.

The Finalize() 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() 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.

Functions

Cancel()

Cancels the streaming RPC, terminating any pending operations.

Returns
TypeDescription
void

UploadId() const

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

Returns
TypeDescription
std::string

PersistedState() const

Returns the last known state of the upload.

Updated during initialization and by successful Query() or Finalize() requests.

Returns
TypeDescription
absl::variant< std::int64_t, storage::ObjectMetadata >

Write(WritePayload)

Uploads some data to the service.

Parameter
NameDescription
payload WritePayload
Returns
TypeDescription
future< Status >

Finalize(WritePayload)

Finalizes an upload.

Parameter
NameDescription
WritePayload
Returns
TypeDescription
future< StatusOr< storage::ObjectMetadata > >

Flush(WritePayload)

Uploads some data to the service and flushes the value.

Parameter
NameDescription
payload WritePayload
Returns
TypeDescription
future< Status >

Query()

Wait for the result of a Flush() call.

Returns
TypeDescription
future< StatusOr< std::int64_t > >

GetRequestMetadata()

Return the request metadata.

Returns
TypeDescription
RpcMetadata