1.13.0 • Published 5 years ago

webiny-file-storage-s3 v1.13.0

Weekly downloads
31
License
MIT
Repository
github
Last release
5 years ago

webiny-file-storage-s3

AWS S3 driver for webiny-file-storage interface.

Documentation

Table of Contents

About

This is the AWS S3 driver for webiny-file-storage. The driver allows you to store files to S3.

Get started

The S3 driver takes a config object defined by S3StorageDriverConfig flow type. The S3StorageDriverConfig takes the following parameters:

S3StorageDriverConfig = {
    bucket: string,             /* required */
    accessKeyId: string,        /* required */
    secretAccessKey: string,    /* required */
    region: string,             /* required */
    endpoint: string,           /* required */
    createDatePrefix: boolean,
    directory: string,
    publicUrl: string
};

Classes

S3StorageDriver

packages-utils/webiny-file-storage-s3/src/index.js:45-387

S3StorageDriver class instance is the AWS S3 driver for webiny-file-storage.

Examples

import S3StorageDriver from "webiny-file-storage-s3";
import type { S3StorageDriverConfig } from "webiny-file-storage-s3";

const params: S3StorageDriverConfig = {
    bucket: "TestBucket",
    accessKeyId: "AWS_AccessKeyId",
    secretAccessKey: "AWS_SecretAccessKey",
    region: "us-east-2",
    endpoint: "s3.us-east-2.amazonaws.com"
};

const s3Storage = new S3StorageDriver(S3StorageDriverConfig);
s3Storage.getFile("fileKey");
getFile

packages-utils/webiny-file-storage-s3/src/index.js:60-72

Returns the file and its content.

Parameters

  • key string This is the file identifier under which the file is stored.
  • options Object This is the list of additional parameters - defined by IFileStorageDriver, but not used in case of this driver.

Returns Promise<IFileData> IFileData object.

setFile

packages-utils/webiny-file-storage-s3/src/index.js:80-118

Writes the given file and returns final file key.

Parameters

  • key string This is the file identifier under which the file will be stored.
  • file IFileData This is the IFileData object containing the content and meta information.

Returns Promise<string> The final key under which the file is stored.

getMeta

packages-utils/webiny-file-storage-s3/src/index.js:125-137

Returns file meta information.

Parameters

  • key string This is the file identifier under which the file is stored.

Returns Promise<Object> Object containing the file meta information.

setMeta

packages-utils/webiny-file-storage-s3/src/index.js:145-153

Sets file meta information. Tne new meta information is merged with the existing meta information.

Parameters

  • key string This is the file identifier under which the file is stored.
  • meta Object This is the object containing the new meta information that will be added to the file.

Returns Promise<boolean> Returns true if meta has been set successfully, otherwise false.

exists

packages-utils/webiny-file-storage-s3/src/index.js:160-166

Returns true if the file exists, otherwise false.

Parameters

  • key string This is the file identifier under which the file is stored.

Returns Promise<boolean>

getKeys

packages-utils/webiny-file-storage-s3/src/index.js:177-212

Returns an array of all keys. In case of S3, the key parameter is used as a Prefix filter. Once the results matching this filter have been retrieved a regex match with filter param is applied and then all matching files are returned.

Parameters

  • key string This is the "Prefix" filter.
  • filter string (Optional) Additional regex filter that will be applied

Returns Promise<Array> Array of file keys that match the given filters.

delete

packages-utils/webiny-file-storage-s3/src/index.js:219-230

Delete the file.

Parameters

  • key string This is the file identifier under which the file is stored.

Returns Promise<boolean> true if the file is deleted successfully, otherwise false.

rename

packages-utils/webiny-file-storage-s3/src/index.js:238-259

Rename the file.

Parameters

  • sourceKey string This is the new file key.
  • targetKey string This is the current file identifier under which the file is stored.

Returns Promise<boolean> true if the file is renamed successfully, otherwise false.

getURL

packages-utils/webiny-file-storage-s3/src/index.js:270-276

Returns the public file url. In case the publicUrl param is defined in the S3StorageDriverConfig the public url will return publicUrl+key. In case the publicUrl param is not defined, the method uses the endpoint and bucket param to form the public url.

Parameters

  • key string This is the file identifier under which the file is stored.

Returns string Public URL.

getSize

packages-utils/webiny-file-storage-s3/src/index.js:284-297

Get file size in bytes.

Parameters

  • key string This is the file identifier under which the file is stored.

Returns Promise<number> Number of bytes.

getTimeModified

packages-utils/webiny-file-storage-s3/src/index.js:305-316

Get file last modified time.

Parameters

  • key string This is the file identifier under which the file is stored.

Returns Promise<number> Unix timestamp.

getContentType

packages-utils/webiny-file-storage-s3/src/index.js:324-332

Get file content type.

Parameters

  • key string This is the file identifier under which the file is stored.

Returns Promise<string> File content type.

1.13.0

5 years ago

1.12.7

5 years ago

1.12.6

5 years ago

1.12.5

5 years ago

1.12.4

5 years ago

1.12.3

5 years ago

1.12.2

5 years ago

1.12.1

5 years ago

1.12.0

5 years ago

1.11.0

5 years ago

1.10.5

5 years ago

1.10.4

5 years ago

1.10.3

5 years ago

1.10.2

5 years ago

1.10.1

5 years ago

1.10.0

5 years ago

1.9.0

5 years ago

1.8.1

5 years ago

1.8.0

5 years ago

1.7.0

5 years ago

1.6.0

5 years ago

1.5.1

5 years ago

1.5.0

5 years ago

1.4.0

5 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago