Create a TransferManager object to perform parallel transfer operations on a Cloud Storage bucket.
Package
@google-cloud/storageConstructors
(constructor)(bucket)
constructor
(
bucket
:
Bucket
);
Constructs a new instance of the TransferManager
class
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.
const
{
Storage
}
=
require
(
' @google-cloud/storage
'
);
const
storage
=
new
Storage
();
const
bucket
=
storage
.
bucket
(
'my-bucket'
);
const
transferManager
=
new
TransferManager
(
bucket
);
//-
// Download a large file in chunks utilizing parallel operations.
//-
const
response
=
await
transferManager
.
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.
filesOrFolder
File
[] | 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.
options
const
{
Storage
}
=
require
(
' @google-cloud/storage
'
);
const
storage
=
new
Storage
();
const
bucket
=
storage
.
bucket
(
'my-bucket'
);
const
transferManager
=
new
TransferManager
(
bucket
);
//-
// Download multiple files in parallel.
//-
const
response
=
await
transferManager
.
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)
const
response
=
await
transferManager
.
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)
const
response
=
await
transferManager
.
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.
filePath
string
The path of the file to be uploaded
options
generator
MultiPartHelperGenerator
A function that will return a type that implements the MPU interface. Most users will not need to use this.
Promise
< GaxiosResponse
| undefined>
{Promise
const
{
Storage
}
=
require
(
' @google-cloud/storage
'
);
const
storage
=
new
Storage
();
const
bucket
=
storage
.
bucket
(
'my-bucket'
);
const
transferManager
=
new
TransferManager
(
bucket
);
//-
// Upload a large file in chunks utilizing parallel operations.
//-
const
response
=
await
transferManager
.
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.
filePathsOrDirectory
string[] | 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
options
const
{
Storage
}
=
require
(
' @google-cloud/storage
'
);
const
storage
=
new
Storage
();
const
bucket
=
storage
.
bucket
(
'my-bucket'
);
const
transferManager
=
new
TransferManager
(
bucket
);
//-
// Upload multiple files in parallel.
//-
const
response
=
await
transferManager
.
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
'
maintaining
the
subdirectory
structure
.