Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow setting timeouts on uploads #1208

Merged
merged 2 commits into from Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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