@@ -27,6 +27,7 @@ import * as resumableUpload from './resumable-upload.js';
2727import { Writable , Readable , pipeline , Transform , PipelineSource } from 'stream' ;
2828import * as zlib from 'zlib' ;
2929import * as http from 'http' ;
30+ import { randomUUID } from 'crypto' ;
3031
3132import {
3233 ExceptionMessages ,
@@ -266,6 +267,14 @@ export interface CreateWriteStreamOptions extends CreateResumableUploadOptions {
266267 validation ?: string | boolean ;
267268}
268269
270+ /**
271+ * @internal
272+ */
273+ export interface CreateWriteStreamOptionsInternal
274+ extends CreateWriteStreamOptions {
275+ invocationId ?: string ;
276+ }
277+
269278export interface MakeFilePrivateOptions {
270279 metadata ?: FileMetadata ;
271280 strict ?: boolean ;
@@ -2213,7 +2222,10 @@ class File extends ServiceObject<File, FileMetadata> {
22132222
22142223 writeStream . once ( 'writing' , async ( ) => {
22152224 if ( options . resumable === false ) {
2216- await this . startSimpleUpload_ ( fileWriteStream , options ) ;
2225+ await this . startSimpleUpload_ (
2226+ fileWriteStream ,
2227+ options as CreateWriteStreamOptionsInternal ,
2228+ ) ;
22172229 } else {
22182230 await this . startResumableUpload_ ( fileWriteStream , options ) ;
22192231 }
@@ -4219,13 +4231,17 @@ class File extends ServiceObject<File, FileMetadata> {
42194231 ) {
42204232 maxRetries = 0 ;
42214233 }
4234+ const persistentInvocationId = randomUUID ( ) ;
42224235 const returnValue = AsyncRetry (
42234236 async ( bail : ( err : Error ) => void ) => {
42244237 return new Promise < void > ( ( resolve , reject ) => {
42254238 if ( maxRetries === 0 ) {
42264239 this . storage . retryOptions . autoRetry = false ;
42274240 }
4228- const writable = this . createWriteStream ( options ) ;
4241+ const writable = this . createWriteStream ( {
4242+ ...options ,
4243+ invocationId : persistentInvocationId ,
4244+ } as CreateWriteStreamOptionsInternal ) ;
42294245
42304246 if ( options . onUploadProgress ) {
42314247 writable . on ( 'progress' , options . onUploadProgress ) ;
@@ -4532,7 +4548,7 @@ class File extends ServiceObject<File, FileMetadata> {
45324548 */
45334549 startSimpleUpload_ (
45344550 dup : Duplexify ,
4535- options : CreateWriteStreamOptions = { } ,
4551+ options : CreateWriteStreamOptionsInternal = { } ,
45364552 ) : void {
45374553 options . metadata ??= { } ;
45384554
@@ -4546,6 +4562,7 @@ class File extends ServiceObject<File, FileMetadata> {
45464562 uploadType : 'multipart' ,
45474563 } ,
45484564 url,
4565+ invocationId : options . invocationId ,
45494566 [ GCCL_GCS_CMD_KEY ] : options [ GCCL_GCS_CMD_KEY ] ,
45504567 method : 'POST' ,
45514568 responseType : 'json' ,
0 commit comments