Skip to content

Commit

Permalink
feat: allow setting timeouts on uploads (#1208)
Browse files Browse the repository at this point in the history
Co-authored-by: Jonathan Lui <jonathanlui@google.com>
  • Loading branch information
stephenplusplus and jkwlui committed Jun 11, 2020
1 parent bcd77cd commit 01b3691
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/bucket.ts
Expand Up @@ -347,6 +347,7 @@ export interface UploadOptions
encryptionKey?: string | Buffer;
kmsKeyName?: string;
resumable?: boolean;
timeout?: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onUploadProgress?: (progressEvent: any) => void;
}
Expand Down Expand Up @@ -3239,6 +3240,9 @@ class Bucket extends ServiceObject {
* `options.predefinedAcl = 'publicRead'`)
* @param {boolean} [options.resumable] Force a resumable upload. (default:
* true for files larger than 5 MB).
* @param {number} [options.timeout=60000] Set the HTTP request timeout in
* milliseconds. This option is not available for resumable uploads.
* Default: `60000`
* @param {string} [options.uri] The URI for an already-created resumable
* upload. See {@link File#createResumableUpload}.
* @param {string} [options.userProject] The ID of the project which will be
Expand Down
13 changes: 9 additions & 4 deletions src/file.ts
Expand Up @@ -211,6 +211,7 @@ export interface CreateWriteStreamOptions extends CreateResumableUploadOptions {
contentType?: string;
gzip?: string | boolean;
resumable?: boolean;
timeout?: number;
validation?: string | boolean;
}

Expand Down Expand Up @@ -1573,6 +1574,9 @@ class File extends ServiceObject<File> {
* working with streams, the file format and size is unknown until it's
* completely consumed. Because of this, it's best for you to be explicit
* for what makes sense given your input.
* @param {number} [timeout=60000] Set the HTTP request timeout in
* milliseconds. This option is not available for resumable uploads.
* Default: `60000`
* @property {string} [uri] The URI for an already-created resumable
* upload. See {@link File#createResumableUpload}.
* @property {string} [userProject] The ID of the project which will be
Expand Down Expand Up @@ -3564,10 +3568,7 @@ class File extends ServiceObject<File> {
*
* @private
*/
startSimpleUpload_(
dup: Duplexify,
options?: CreateResumableUploadOptions
): void {
startSimpleUpload_(dup: Duplexify, options?: CreateWriteStreamOptions): void {
options = Object.assign(
{
metadata: {},
Expand All @@ -3594,6 +3595,10 @@ class File extends ServiceObject<File> {
reqOpts.qs.kmsKeyName = this.kmsKeyName;
}

if (typeof options.timeout === 'number') {
reqOpts.timeout = options.timeout;
}

if (options.userProject || this.userProject) {
reqOpts.qs.userProject = options.userProject || this.userProject;
}
Expand Down
2 changes: 2 additions & 0 deletions test/file.ts
Expand Up @@ -4151,6 +4151,7 @@ describe('File', () => {
predefinedAcl: 'allUsers',
private: true,
public: true,
timeout: 99,
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -4161,6 +4162,7 @@ describe('File', () => {
name: file.name,
predefinedAcl: options.predefinedAcl,
},
timeout: options.timeout,
uri:
'https://storage.googleapis.com/upload/storage/v1/b/' +
file.bucket.name +
Expand Down

0 comments on commit 01b3691

Please sign in to comment.