Class TransferManager (7.16.0)

Create a TransferManager object to perform parallel transfer operations on a Cloud Storage bucket.

Package

@google-cloud/storage

Constructors

(constructor)(bucket)

constructor(bucket:Bucket);

Constructs a new instance of theTransferManager class

Parameter
NameDescription
bucketBucket

Properties

bucket

bucket:Bucket;

Methods

downloadFileInChunks(fileOrName, options)

downloadFileInChunks(fileOrName:File|string,options?:DownloadFileInChunksOptions):Promise<void|DownloadResponse>;

Download a large file in chunks utilizing parallel download operations. This is a convenience method that utilizes to perform the download.

Parameters
NameDescription
fileOrNameFile | string

to download.

optionsDownloadFileInChunksOptions

Configuration options.

Returns
TypeDescription
Promise<void |DownloadResponse>

{Promise<void | DownloadResponse>}

Example
const{Storage}=require('@google-cloud/storage');conststorage=newStorage();constbucket=storage.bucket('my-bucket');consttransferManager=newTransferManager(bucket);//-// Download a large file in chunks utilizing parallel operations.//-constresponse=awaittransferManager.downloadFileInChunks(bucket.file('large-file.txt');// Your local directory now contains:// - "large-file.txt" (with the contents from my-bucket.large-file.txt)

downloadManyFiles(filesOrFolder, options)

downloadManyFiles(filesOrFolder:File[]|string[]|string,options?:DownloadManyFilesOptions):Promise<void|DownloadResponse[]>;

Download multiple files in parallel to the local filesystem. This is a convenience method that utilizes to perform the download.

Parameters
NameDescription
filesOrFolderFile[] | string[] | string

An array of file name strings or file objects to be downloaded. If a string is provided this will be treated as a GCS prefix and all files with that prefix will be downloaded.

optionsDownloadManyFilesOptions

Configuration options. Setting options.prefix or options.stripPrefix or options.passthroughOptions.destination will cause the downloaded files to be written to the file system instead of being returned as a buffer.

Returns
TypeDescription
Promise<void |DownloadResponse[]>

{Promise<DownloadResponse[]>}

Example
const{Storage}=require('@google-cloud/storage');conststorage=newStorage();constbucket=storage.bucket('my-bucket');consttransferManager=newTransferManager(bucket);//-// Download multiple files in parallel.//-constresponse=awaittransferManager.downloadManyFiles(['file1.txt','file2.txt']);// The following files have been downloaded:// - "file1.txt" (with the contents from my-bucket.file1.txt)// - "file2.txt" (with the contents from my-bucket.file2.txt)constresponse=awaittransferManager.downloadManyFiles([bucket.File('file1.txt'),bucket.File('file2.txt')]);// The following files have been downloaded:// - "file1.txt" (with the contents from my-bucket.file1.txt)// - "file2.txt" (with the contents from my-bucket.file2.txt)constresponse=awaittransferManager.downloadManyFiles('test-folder');// All files with GCS prefix of 'test-folder' have been downloaded.

uploadFileInChunks(filePath, options, generator)

uploadFileInChunks(filePath:string,options?:UploadFileInChunksOptions,generator?:MultiPartHelperGenerator):Promise<GaxiosResponse|undefined>;

Upload a large file in chunks utilizing parallel upload opertions. If the upload fails, an uploadId and map containing all the successfully uploaded parts will be returned to the caller. These arguments can be used to resume the upload.

Parameters
NameDescription
filePathstring

The path of the file to be uploaded

optionsUploadFileInChunksOptions

Configuration options.

generatorMultiPartHelperGenerator

A function that will return a type that implements the MPU interface. Most users will not need to use this.

Returns
TypeDescription
Promise<GaxiosResponse | undefined>

{Promise

Example
const{Storage}=require('@google-cloud/storage');conststorage=newStorage();constbucket=storage.bucket('my-bucket');consttransferManager=newTransferManager(bucket);//-// Upload a large file in chunks utilizing parallel operations.//-constresponse=awaittransferManager.uploadFileInChunks('large-file.txt');// Your bucket now contains:// - "large-file.txt"

uploadManyFiles(filePathsOrDirectory, options)

uploadManyFiles(filePathsOrDirectory:string[]|string,options?:UploadManyFilesOptions):Promise<UploadResponse[]>;

Upload multiple files in parallel to the bucket. This is a convenience method that utilizes to perform the upload.

Parameters
NameDescription
filePathsOrDirectorystring[] | string

An array of fully qualified paths to the files or a directory name. If a directory name is provided, the directory will be recursively walked and all files will be added to the upload list. to be uploaded to the bucket

optionsUploadManyFilesOptions

Configuration options.

Returns
TypeDescription
Promise<UploadResponse[]>

{Promise<UploadResponse[]>}

Example
const{Storage}=require('@google-cloud/storage');conststorage=newStorage();constbucket=storage.bucket('my-bucket');consttransferManager=newTransferManager(bucket);//-// Upload multiple files in parallel.//-constresponse=awaittransferManager.uploadManyFiles(['/local/path/file1.txt, 'local/path/file2.txt']);// Your bucket now contains:// - "local/path/file1.txt" (with the contents of '/local/path/file1.txt')// - "local/path/file2.txt" (with the contents of '/local/path/file2.txt')const response = await transferManager.uploadManyFiles('/local/directory');// Your bucket will now contain all files contained in '/local/directory'maintainingthesubdirectorystructure.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-10-30 UTC.