Google API Core Client - Class ResumableUpload (1.51.0)

Reference documentation and code samples for the Google API Core Client class ResumableUpload.

User-facing object returned when a resumable upload method is called.

Contains the ResumableUploadClient and manages the upload operation.

NOTE: The ResumableUpload class is designed for standard, single-threaded PHP execution environments such as PHP-FPM and PHP-CLI. Concurrency controls are out of scope. If pause() or cancel() are called, they will block and execute synchronously. ResumableUpload instances are NOT thread-safe, and should not be shared across concurrent asynchronous contexts (such as parallel Fibers or Swoole coroutines) without external synchronization.

Namespace

Google \ ApiCore \ ResumableUpload

Methods

__construct

Parameters
Name Description
resumableUploadClient ResumableUploadClient
call Google\ApiCore\Call
callOptions array

Optional.

↳ headers array

Optional. Key-value array of custom HTTP headers to include with upload requests.

↳ timeoutMillis int

Optional. The timeout in milliseconds for the initial start call.

↳ retrySettings RetrySettings|array

Optional. Retry settings to use for the initial start call.

uploadUrl ?string

An existing resumable upload session URL to resume an upload across process restarts or interruptions.

chunkSize ?int

Optional. The chunk size in bytes for the upload.

getUploadUrl

Returns the resumable upload session URL, if available.

This URL can be persisted and used later with $client->resumeUpload($methodName, $uploadUrl) to resume the upload across process restarts or background jobs.

Returns
Type Description
?string

setUploadUrl

Sets the resumable upload session URL.

Parameter
Name Description
uploadUrl string
Returns
Type Description
void

getChunkSize

Returns the actual chunk size in bytes used for the upload, if determined.

This may be the user-specified chunk size, or the chunk size adjusted to match the server-specified chunk granularity.

Returns
Type Description
?int

setChunkSize

Sets the chunk size in bytes for the upload.

Parameter
Name Description
chunkSize int
Returns
Type Description
void

startUpload

Starts or resumes the resumable upload exchange using the provided data stream.

If this instance already has an uploadUrl (e.g. created via $client->resumeUpload($methodName, $uploadUrl) or after a previous start/interruption), calling startUpload($dataStream, $resumableUploadOptions) queries the server for the current byte offset and resumes transmitting remaining chunks.

When resuming an upload, it is recommended that the data stream is rewound to offset 0. If the stream is not rewound and not seekable, an error may occur if unconfirmed chunks must be re-read.

Parameters
Name Description
dataStream Psr\Http\Message\StreamInterface
resumableUploadOptions array

Optional.

↳ chunkSize int

Optional. The size of each chunk to upload in bytes. Must be a multiple of 262144 (256 KB). Values smaller than the server's chunk granularity (typically 256 KB) will be rounded up to match the granularity. Defaults to 8388608 (8 MB).

↳ progressCallback callable

Optional. A callback function executed after every chunk upload or query. The callback should accept two arguments: (int $bytesUploaded, ResumableUpload $upload).

↳ totalTimeoutMillis int

Optional. The total timeout in milliseconds for the entire resumable upload operation. Defaults to 600000 (10 minutes) when stall control is not enabled; when stall control is enabled, no default is set.

↳ transferStallMinimumRate int

Optional. The minimum data transfer speed in MiB/s for stall control. Must be set together with transferStallTimeout.

↳ transferStallTimeout int

Optional. The stall timeout interval in seconds for stall control. Must be set together with transferStallMinimumRate.

Returns
Type Description
Google\Protobuf\Internal\Message