gcs-resumable-upload

  • Version 3.3.1
  • Published
  • 73.7 kB
  • 7 dependencies
  • MIT license

Install

npm i gcs-resumable-upload
yarn add gcs-resumable-upload
pnpm add gcs-resumable-upload

Overview

Upload a file to Google Cloud Storage with built-in resumable behavior

Index

Variables

variable PROTOCOL_REGEX

const PROTOCOL_REGEX: RegExp;

    Functions

    function createURI

    createURI: {
    (cfg: UploadConfig): Promise<string>;
    (cfg: UploadConfig, callback: CreateUriCallback): void;
    };

      function upload

      upload: (cfg: UploadConfig) => Upload;

        Classes

        class Upload

        class Upload extends Pumpify {}

          constructor

          constructor(cfg: UploadConfig);

            property apiEndpoint

            apiEndpoint: string;

              property authClient

              authClient: { request: <T = any>(opts: any) => any };

                property authConfig

                authConfig?: { scopes?: string[] };

                  property baseURI

                  baseURI: string;

                    property bucket

                    bucket: string;

                      property cacheKey

                      cacheKey: string;

                        property configStore

                        configStore: any;

                          property contentLength

                          contentLength: number | '*';

                            property customRequestOptions

                            customRequestOptions: any;

                              property encryption

                              encryption?: Encryption;

                                property file

                                file: string;

                                  property generation

                                  generation?: number;

                                    property key

                                    key?: any;

                                      property kmsKeyName

                                      kmsKeyName?: string;

                                        property maxRetryDelay

                                        maxRetryDelay: number;

                                          property maxRetryTotalTimeout

                                          maxRetryTotalTimeout: number;

                                            property metadata

                                            metadata: ConfigMetadata;

                                              property numBytesWritten

                                              numBytesWritten: number;

                                                property numRetries

                                                numRetries: number;

                                                  property offset

                                                  offset?: number;

                                                    property origin

                                                    origin?: string;

                                                      property params

                                                      params: QueryParameters;

                                                        property predefinedAcl

                                                        predefinedAcl?: PredefinedAcl;

                                                          property private

                                                          private?: boolean;

                                                            property public

                                                            public?: boolean;

                                                              property retryableErrorFn

                                                              retryableErrorFn?: (err: ApiError) => boolean;

                                                                property retryDelayMultiplier

                                                                retryDelayMultiplier: number;

                                                                  property retryLimit

                                                                  retryLimit: number;

                                                                    property timeOfFirstRequest

                                                                    timeOfFirstRequest: number;

                                                                      property uri

                                                                      uri?: string;

                                                                        property uriProvidedManually

                                                                        uriProvidedManually: boolean;

                                                                          property userProject

                                                                          userProject?: string;

                                                                            method createURI

                                                                            createURI: { (): Promise<string>; (callback: CreateUriCallback): void };

                                                                              method createURIAsync

                                                                              protected createURIAsync: () => Promise<string>;

                                                                                method deleteConfig

                                                                                deleteConfig: () => void;

                                                                                  Interfaces

                                                                                  interface ApiError

                                                                                  interface ApiError extends Error {}

                                                                                    property code

                                                                                    code?: number;

                                                                                      interface ConfigMetadata

                                                                                      interface ConfigMetadata {}

                                                                                        property contentLength

                                                                                        contentLength?: number;
                                                                                        • Set the length of the file being uploaded.

                                                                                        property contentType

                                                                                        contentType?: string;
                                                                                        • Set the content type of the incoming data.

                                                                                        index signature

                                                                                        [key: string]: any;

                                                                                          interface Encryption

                                                                                          interface Encryption {}

                                                                                            property hash

                                                                                            hash: {};

                                                                                              property key

                                                                                              key: {};

                                                                                                interface ErrorWithCode

                                                                                                interface ErrorWithCode extends Error {}

                                                                                                  property code

                                                                                                  code: number;

                                                                                                    interface QueryParameters

                                                                                                    interface QueryParameters {}

                                                                                                      property contentEncoding

                                                                                                      contentEncoding?: string;

                                                                                                        property ifGenerationMatch

                                                                                                        ifGenerationMatch?: number;

                                                                                                          property ifGenerationNotMatch

                                                                                                          ifGenerationNotMatch?: number;

                                                                                                            property ifMetagenerationMatch

                                                                                                            ifMetagenerationMatch?: number;

                                                                                                              property ifMetagenerationNotMatch

                                                                                                              ifMetagenerationNotMatch?: number;

                                                                                                                property kmsKeyName

                                                                                                                kmsKeyName?: string;

                                                                                                                  property predefinedAcl

                                                                                                                  predefinedAcl?: PredefinedAcl;

                                                                                                                    property projection

                                                                                                                    projection?: 'full' | 'noAcl';

                                                                                                                      property userProject

                                                                                                                      userProject?: string;

                                                                                                                        interface RetryOptions

                                                                                                                        interface RetryOptions {}

                                                                                                                          property autoRetry

                                                                                                                          autoRetry?: boolean;

                                                                                                                            property maxRetries

                                                                                                                            maxRetries?: number;

                                                                                                                              property maxRetryDelay

                                                                                                                              maxRetryDelay?: number;

                                                                                                                                property retryableErrorFn

                                                                                                                                retryableErrorFn?: (err: ApiError) => boolean;

                                                                                                                                  property retryDelayMultiplier

                                                                                                                                  retryDelayMultiplier?: number;

                                                                                                                                    property totalTimeout

                                                                                                                                    totalTimeout?: number;

                                                                                                                                      interface UploadConfig

                                                                                                                                      interface UploadConfig {}

                                                                                                                                        property apiEndpoint

                                                                                                                                        apiEndpoint?: string;
                                                                                                                                        • The API endpoint used for the request. Defaults to storage.googleapis.com. **Warning**: If this value does not match the pattern *.googleapis.com, an emulator context will be assumed and authentication will be bypassed.

                                                                                                                                        property authClient

                                                                                                                                        authClient?: {
                                                                                                                                        request: <T = any>(
                                                                                                                                        opts: GaxiosOptions
                                                                                                                                        ) => Promise<GaxiosResponse<T>> | GaxiosPromise<T>;
                                                                                                                                        };
                                                                                                                                        • If you want to re-use an auth client from google-auto-auth, pass an instance here. Defaults to GoogleAuth and gets automatically overridden if an emulator context is detected.

                                                                                                                                        property authConfig

                                                                                                                                        authConfig?: GoogleAuthOptions;
                                                                                                                                        • The GoogleAuthOptions passed to google-auth-library

                                                                                                                                        property bucket

                                                                                                                                        bucket: string;
                                                                                                                                        • The name of the destination bucket.

                                                                                                                                        property configPath

                                                                                                                                        configPath?: string;
                                                                                                                                        • Where the gcs-resumable-upload configuration file should be stored on your system. This maps to the configstore option by the same name.

                                                                                                                                        property customRequestOptions

                                                                                                                                        customRequestOptions?: GaxiosOptions;
                                                                                                                                        • For each API request we send, you may specify custom request options that we'll add onto the request. The request options follow the gaxios API: https://github.com/googleapis/gaxios#request-options.

                                                                                                                                        property file

                                                                                                                                        file: string;
                                                                                                                                        • The name of the destination file.

                                                                                                                                        property generation

                                                                                                                                        generation?: number;
                                                                                                                                        • This will cause the upload to fail if the current generation of the remote object does not match the one provided here.

                                                                                                                                        property key

                                                                                                                                        key?: string | Buffer;
                                                                                                                                        • A customer-supplied encryption key. See https://cloud.google.com/storage/docs/encryption#customer-supplied.

                                                                                                                                        property kmsKeyName

                                                                                                                                        kmsKeyName?: string;
                                                                                                                                        • Resource name of the Cloud KMS key, of the form projects/my-project/locations/global/keyRings/my-kr/cryptoKeys/my-key, that will be used to encrypt the object. Overrides the object metadata's kms_key_name value, if any.

                                                                                                                                        property metadata

                                                                                                                                        metadata?: ConfigMetadata;
                                                                                                                                        • Any metadata you wish to set on the object.

                                                                                                                                        property offset

                                                                                                                                        offset?: number;
                                                                                                                                        • The starting byte of the upload stream, for resuming an interrupted upload. See https://cloud.google.com/storage/docs/json_api/v1/how-tos/resumable-upload#resume-upload.

                                                                                                                                        property origin

                                                                                                                                        origin?: string;
                                                                                                                                        • Set an Origin header when creating the resumable upload URI.

                                                                                                                                        property params

                                                                                                                                        params?: QueryParameters;
                                                                                                                                        • Specify query parameters that go along with the initial upload request. See https://cloud.google.com/storage/docs/json_api/v1/objects/insert#parameters

                                                                                                                                        property predefinedAcl

                                                                                                                                        predefinedAcl?: PredefinedAcl;
                                                                                                                                        • Apply a predefined set of access controls to the created file.

                                                                                                                                        property private

                                                                                                                                        private?: boolean;
                                                                                                                                        • Make the uploaded file private. (Alias for config.predefinedAcl = 'private')

                                                                                                                                        property public

                                                                                                                                        public?: boolean;
                                                                                                                                        • Make the uploaded file public. (Alias for config.predefinedAcl = 'publicRead')

                                                                                                                                        property retryOptions

                                                                                                                                        retryOptions?: RetryOptions;
                                                                                                                                        • Configuration options for retrying retriable errors.

                                                                                                                                        property uri

                                                                                                                                        uri?: string;
                                                                                                                                        • If you already have a resumable URI from a previously-created resumable upload, just pass it in here and we'll use that.

                                                                                                                                        property userProject

                                                                                                                                        userProject?: string;
                                                                                                                                        • If the bucket being accessed has requesterPays functionality enabled, this can be set to control which project is billed for the access of this file.

                                                                                                                                        Type Aliases

                                                                                                                                        type CreateUriCallback

                                                                                                                                        type CreateUriCallback = (err: Error | null, uri?: string) => void;

                                                                                                                                          type PredefinedAcl

                                                                                                                                          type PredefinedAcl =
                                                                                                                                          | 'authenticatedRead'
                                                                                                                                          | 'bucketOwnerFullControl'
                                                                                                                                          | 'bucketOwnerRead'
                                                                                                                                          | 'private'
                                                                                                                                          | 'projectPrivate'
                                                                                                                                          | 'publicRead';

                                                                                                                                            Package Files (1)

                                                                                                                                            Dependencies (7)

                                                                                                                                            Dev Dependencies (18)

                                                                                                                                            Peer Dependencies (0)

                                                                                                                                            No peer dependencies.

                                                                                                                                            Badge

                                                                                                                                            To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                            You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/gcs-resumable-upload.

                                                                                                                                            • Markdown
                                                                                                                                              [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/gcs-resumable-upload)
                                                                                                                                            • HTML
                                                                                                                                              <a href="https://www.jsdocs.io/package/gcs-resumable-upload"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>