Skip to main content

@webda/awsReadme | API


Class: S3Binary<T>

S3Binary handles the storage of binary on a S3 bucket

The structure used for now is /{hash}/data /{hash}/{targetStore}_{uuid} The challenge is stored on the metadata of the data object

It takes parameters bucket: "bucketName" accessKeyId: "" secretAccessKey: "" region: ""

See Binary the general interface

We can register on S3 Event to get info when /data is pushed

Webda Modda

Extends

  • CloudBinary<T>

Type parameters

T extends S3BinaryParameters = S3BinaryParameters

Implements

Constructors

new S3Binary(webda, name, params)

new S3Binary<T>(webda, name, params?): S3Binary<T>

Parameters

webda: Core<CoreEvents>

The main instance of Webda

name: string

The name of the service

params?: DeepPartial<T>

The parameters block define in the configuration file

Returns

S3Binary<T>

Inherited from

CloudBinary<T>.constructor

Source

packages/core/lib/services/service.d.ts:168

Properties

_createException

_createException: string

Inherited from

CloudBinary._createException

Source

packages/core/lib/services/service.d.ts:149


_initException

_initException: any

Inherited from

CloudBinary._initException

Source

packages/core/lib/services/service.d.ts:151


_initTime

_initTime: number

Inherited from

CloudBinary._initTime

Source

packages/core/lib/services/service.d.ts:150


_lowercaseMaps

_lowercaseMaps: any

Inherited from

CloudBinary._lowercaseMaps

Source

packages/core/lib/services/binary.d.ts:370


_name

protected _name: string

Service name

Inherited from

CloudBinary._name

Source

packages/core/lib/services/service.d.ts:142


_s3

_s3: S3

Source

packages/aws/src/services/s3binary.ts:61


_webda

protected _webda: Core<CoreEvents>

Webda Core object

Inherited from

CloudBinary._webda

Source

packages/core/lib/services/service.d.ts:138


logger

protected logger: Logger

Logger with class context

Inherited from

CloudBinary.logger

Source

packages/core/lib/services/service.d.ts:155


metrics

metrics: Object

Type declaration

delete

delete: Counter<string>

download

download: Counter<string>

metadataUpdate

metadataUpdate: Counter<string>

upload

upload: Counter<string>

Inherited from

CloudBinary.metrics

Source

packages/core/lib/services/binary.d.ts:371


parameters

protected parameters: T

Hold the parameters for your service

It will be bring from the webda.config.json

Inherited from

CloudBinary.parameters

Source

packages/core/lib/services/service.d.ts:148


captureRejectionSymbol

static readonly captureRejectionSymbol: typeof captureRejectionSymbol

Inherited from

CloudBinary.captureRejectionSymbol

Source

node_modules/@types/node/events.d.ts:38


captureRejections

static captureRejections: boolean

Sets or gets the default captureRejection value for all emitters.

Inherited from

CloudBinary.captureRejections

Source

node_modules/@types/node/events.d.ts:44


defaultMaxListeners

static defaultMaxListeners: number

Inherited from

CloudBinary.defaultMaxListeners

Source

node_modules/@types/node/events.d.ts:45


errorMonitor

static readonly errorMonitor: typeof errorMonitor

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

Inherited from

CloudBinary.errorMonitor

Source

node_modules/@types/node/events.d.ts:37

Methods

__clean()

__clean(): Promise<void>

Clean the service data, can only be used in test mode

Returns

Promise<void>

Inherited from

CloudBinary.__clean

Abstract

Source

packages/core/lib/services/service.d.ts:319


_cleanHash()

_cleanHash(hash): Promise<void>

Parameters

hash: string

Returns

Promise<void>

Inherit Doc

Source

packages/aws/src/services/s3binary.ts:237


_cleanUsage()

_cleanUsage(hash, uuid, attribute?): Promise<void>

Parameters

hash: string

uuid: string

attribute?: string

Returns

Promise<void>

Overrides

CloudBinary._cleanUsage

Inherit Doc

Source

packages/aws/src/services/s3binary.ts:260


_exists()

_exists(hash): Promise<boolean>

Parameters

hash: string

Returns

Promise<boolean>

Inherit Doc

Source

packages/aws/src/services/s3binary.ts:275


_get()

_get(info): Promise<Readable>

Parameters

info: BinaryMap<any>

Returns

Promise<Readable>

Overrides

CloudBinary._get

Source

packages/aws/src/services/s3binary.ts:193


_getFile()

_getFile(req): Promise<BinaryFile<any>>

Get file either from multipart post or raw

Parameters

req: WebContext<any, any>

Returns

Promise<BinaryFile<any>>

Inherited from

CloudBinary._getFile

Source

packages/core/lib/services/binary.d.ts:508


_getKey()

_getKey(hash, suffix?): string

Return the S3 key

Parameters

hash: string

suffix?: string

Returns

string

Inherited from

CloudBinary._getKey

Source

packages/core/lib/services/cloudbinary.d.ts:29


_getS3()

_getS3(hash): Promise<HeadObjectCommandOutput>

Get a head object

Parameters

hash: string

Returns

Promise<HeadObjectCommandOutput>

Source

packages/aws/src/services/s3binary.ts:295


_initRoutes()

_initRoutes(): void

Init the Binary system routes

Making sure parameters.expose exists prior

Returns

void

Inherited from

CloudBinary._initRoutes

Source

packages/core/lib/services/binary.d.ts:518


_verifyMapAndStore()

_verifyMapAndStore(ctx): Store<CoreModel, StoreParameters, StoreEvents>

Based on the request parameter verify it match a known mapping

Parameters

ctx: WebContext<any, any>

Returns

Store<CoreModel, StoreParameters, StoreEvents>

Inherited from

CloudBinary._verifyMapAndStore

Source

packages/core/lib/services/binary.d.ts:529


addListener()

addListener(event, listener): this

Parameters

event: string | symbol

listener: (...args) => void

Returns

this

Inherited from

CloudBinary.addListener

Source

node_modules/@types/node/events.d.ts:57


addRoute()

protected addRoute(url, methods, executer, openapi?, override?): void

Add a route dynamicaly

Parameters

url: string

of the route can contains dynamic part like {uuid}

methods: HttpMethodType[]

executer: Function

Method to execute for this route

openapi?: OpenAPIWebdaDefinition

override?: boolean

Returns

void

Inherited from

CloudBinary.addRoute

Source

packages/core/lib/services/service.d.ts:242


authorizeClientEvent()

authorizeClientEvent(_event, _context): boolean

Authorize a public event subscription

Parameters

_event: string

_context: OperationContext<any, any>

Returns

boolean

Inherited from

CloudBinary.authorizeClientEvent

Source

packages/core/lib/services/service.d.ts:220


cascadeDelete()

cascadeDelete(info, uuid): Promise<void>

Parameters

info: BinaryMap<any>

uuid: string

Returns

Promise<void>

Inherited from

CloudBinary.cascadeDelete

Inherit Doc

Source

packages/core/lib/services/cloudbinary.d.ts:37


checkMap()

protected checkMap(object, property): void

Check if a map is defined

Parameters

object: CoreModel

property: string

Returns

void

Inherited from

CloudBinary.checkMap

Source

packages/core/lib/services/binary.d.ts:482


computeParameters()

computeParameters(): void

Returns

void

Overrides

CloudBinary.computeParameters

Inherit Doc

Source

packages/aws/src/services/s3binary.ts:75


delete()

delete(object, property, index): Promise<void>

Parameters

object: BinaryModel

property: string

index: number

Returns

Promise<void>

Inherited from

CloudBinary.delete

Inherit Doc

Source

packages/core/lib/services/cloudbinary.d.ts:33


deleteSuccess()

deleteSuccess(object, property, index?): Promise<any>

Parameters

object: BinaryModel<Object>

property: string

index?: number

Returns

Promise<any>

Inherited from

CloudBinary.deleteSuccess

Source

packages/core/lib/services/binary.d.ts:502


downloadTo()

downloadTo(info, filename): Promise<void>

Download a binary to a file

Parameters

info: BinaryMap<any>

The reference stored in your target object

filename: any

Returns

Promise<void>

Inherited from

CloudBinary.downloadTo

Source

packages/core/lib/services/binary.d.ts:451


emit()

emit<Key>(event, data): boolean

Override to allow capturing long listeners

Type parameters

Key extends keyof BinaryEvents

Parameters

event: symbol | Key

data: BinaryEvents[Key]

Returns

boolean

Inherited from

CloudBinary.emit

Source

packages/core/lib/services/service.d.ts:289


emitSync()

emitSync<Key>(event, data): Promise<any[]>

Emit the event with data and wait for Promise to finish if listener returned a Promise

Type parameters

Key extends keyof BinaryEvents

Parameters

event: Key

data: BinaryEvents[Key]

Returns

Promise<any[]>

Inherited from

CloudBinary.emitSync

Source

packages/core/lib/services/service.d.ts:284


eventNames()

eventNames(): (string | symbol)[]

Returns

(string | symbol)[]

Inherited from

CloudBinary.eventNames

Source

node_modules/@types/node/events.d.ts:72


exists()

exists(Key, Bucket): Promise<HeadObjectCommandOutput>

Check if an object exists on S3

Parameters

Key: string

Bucket: string= undefined

Returns

Promise<HeadObjectCommandOutput>

Source

packages/aws/src/services/s3binary.ts:207


forEachFile()

forEachFile(Bucket, callback, Prefix, filter): Promise<void>

Parameters

Bucket: string

to iterate on

callback: (Key, page) => Promise<void>

to execute with each key

Prefix: string= ""

to use

filter: RegExp= undefined

regexp to execute on the key

Returns

Promise<void>

Source

packages/aws/src/services/s3binary.ts:333


get()

get(info): Promise<Readable>

Get a binary

Parameters

info: BinaryMap<any>

The reference stored in your target object

Returns

Promise<Readable>

Inherited from

CloudBinary.get

Emits

'binaryGet'

Source

packages/core/lib/services/binary.d.ts:444


getARNPolicy()

getARNPolicy(_accountId): Object

Parameters

_accountId: string

Returns

Object

Action

Action: string[]

Effect

Effect: string = "Allow"

Resource

Resource: string[]

Sid

Sid: string

Inherit Doc

Source

packages/aws/src/services/s3binary.ts:408


getClientEvents()

getClientEvents(): string[]

Return the events that an external system can subscribe to

Returns

string[]

Inherited from

CloudBinary.getClientEvents

Source

packages/core/lib/services/service.d.ts:214


getCloudFormation()

getCloudFormation(deployer): Object

S3Binary.getCloudFormation

Parameters

deployer: default

The current deployer asking for contribution

Returns

Object

Implementation of

CloudFormationContributor.getCloudFormation

Source

packages/aws/src/services/s3binary.ts:440


getMaxListeners()

getMaxListeners(): number

Returns

number

Inherited from

CloudBinary.getMaxListeners

Source

node_modules/@types/node/events.d.ts:64


getMetric()

getMetric<T>(type, configuration): T

Add service name label

Type parameters

T = Counter<string> | Histogram<string> | Gauge<string>

Parameters

type: Constructor<T, [MetricConfiguration<T>]>

configuration: MetricConfiguration<T>

Returns

T

Inherited from

CloudBinary.getMetric

Source

packages/core/lib/services/service.d.ts:208


getName()

getName(): string

Get service name

Returns

string

Inherited from

CloudBinary.getName

Source

packages/core/lib/services/service.d.ts:313


getObject()

getObject(key, bucket?): Promise<Readable>

Get an object from s3 bucket

Parameters

key: string

to get

bucket?: string

to retrieve from or default bucket

Returns

Promise<Readable>

Source

packages/aws/src/services/s3binary.ts:315


getOpenApiReplacements()

getOpenApiReplacements(): any

Return variables for replacement in openapi

Returns

any

Inherited from

CloudBinary.getOpenApiReplacements

Source

packages/core/lib/services/service.d.ts:247


getOperationId()

getOperationId(id): string

If undefined is returned it cancel the operation registration

Parameters

id: string

Returns

string

Inherited from

CloudBinary.getOperationId

Source

packages/core/lib/services/service.d.ts:234


getOperationName()

protected getOperationName(): string

Return the name of the service for OpenAPI

Returns

string

Inherited from

CloudBinary.getOperationName

Source

packages/core/lib/services/binary.d.ts:523


getParameters()

getParameters(): T

Get the service parameters

Returns

T

Inherited from

CloudBinary.getParameters

Source

packages/core/lib/services/service.d.ts:180


getRedirectUrlFromObject()

getRedirectUrlFromObject(binaryMap, context, expires?): Promise<string>

Get a UrlFromObject

Parameters

binaryMap: any

context: any

expires?: number

Returns

Promise<string>

Inherited from

CloudBinary.getRedirectUrlFromObject

Source

packages/core/lib/services/cloudbinary.d.ts:22


getService()

getService<K>(service): K

Return a webda service

Type parameters

K extends Service<ServiceParameters, Events>

Parameters

service: string

name to retrieve

Returns

K

Inherited from

CloudBinary.getService

Source

packages/core/lib/services/service.d.ts:309


getSignedUrl()

getSignedUrl(key, action, params): Promise<string>

Return a signed url to an object

Parameters

key: string

to the object

action: "getObject" | "putObject"= "getObject"

to perform

params: any= {}

Returns

Promise<string>

Source

packages/aws/src/services/s3binary.ts:164


getSignedUrlFromMap()

getSignedUrlFromMap(binaryMap, expire, _context): Promise<string>

Parameters

binaryMap: BinaryMap<any>

expire: number

_context: OperationContext<any, any>

Returns

Promise<string>

Overrides

CloudBinary.getSignedUrlFromMap

Source

packages/aws/src/services/s3binary.ts:180


getUrl()

getUrl(url, _methods): string

Return the full path url based on parameters

Parameters

url: string

relative url to service

_methods: HttpMethodType[]

in case we need filtering (like Store)

Returns

string

absolute url or undefined if need to skip the Route

Inherited from

CloudBinary.getUrl

Source

packages/core/lib/services/service.d.ts:228


getUsageCount()

getUsageCount(hash): Promise<number>

Parameters

hash: string

Returns

Promise<number>

Overrides

CloudBinary.getUsageCount

Inherit Doc

Source

packages/aws/src/services/s3binary.ts:224


getWebda()

getWebda(): Core<CoreEvents>

Return WebdaCore

Returns

Core<CoreEvents>

Inherited from

CloudBinary.getWebda

Source

packages/core/lib/services/service.d.ts:184


handleBinary()

handleBinary(modelName, attribute): 0 | 1 | -1 | 2

Define if binary is managed by the store

Parameters

modelName: string

attribute: string

Returns

0 | 1 | -1 | 2

-1 if not managed, 0 if managed but by default, 1 if managed and in the map, 2 if explicit with attribute and model

Inherited from

CloudBinary.handleBinary

Source

packages/core/lib/services/binary.d.ts:400


httpChallenge()

httpChallenge(ctx): Promise<void>

Mechanism to add a data based on challenge

Parameters

ctx: WebContext<BinaryFile<any>, any>

Returns

Promise<void>

Inherited from

CloudBinary.httpChallenge

Source

packages/core/lib/services/binary.d.ts:545


httpGet()

httpGet(context): Promise<void>

Redirect to the temporary link to S3 object or return it if returnInfo=true

Parameters

context: WebContext<any, any>

Returns

Promise<void>

Inherited from

CloudBinary.httpGet

Source

packages/core/lib/services/binary.d.ts:388


httpRoute()

httpRoute(ctx): Promise<void>

Manage the different routes

Parameters

ctx: WebContext<any, any>

Returns

Promise<void>

Inherited from

CloudBinary.httpRoute

Source

packages/core/lib/services/binary.d.ts:550


init()

init(): Promise<S3Binary<T>>

Will be called after all the Services are created

Returns

Promise<S3Binary<T>>

Inherited from

CloudBinary.init

Abstract

Source

packages/core/lib/services/service.d.ts:275


initMap()

initMap(map): void

Init the declared maps, adding reverse maps

Parameters

map: any

Returns

void

Inherited from

CloudBinary.initMap

Source

packages/core/lib/services/binary.d.ts:462


initMetrics()

initMetrics(): void

Returns

void

Inherited from

CloudBinary.initMetrics

Source

packages/core/lib/services/binary.d.ts:380


initOperations()

initOperations(): void

Init the operations

Returns

void

Inherited from

CloudBinary.initOperations

Source

packages/core/lib/services/service.d.ts:255


initRoutes()

initRoutes(): void

Returns

void

Inherited from

CloudBinary.initRoutes

Source

packages/core/lib/services/binary.d.ts:512


listenerCount()

listenerCount(event): number

Parameters

event: string | symbol

Returns

number

Inherited from

CloudBinary.listenerCount

Source

node_modules/@types/node/events.d.ts:68


listeners()

listeners(event): Function[]

Parameters

event: string | symbol

Returns

Function[]

Inherited from

CloudBinary.listeners

Source

node_modules/@types/node/events.d.ts:65


loadParameters()

loadParameters(params): S3BinaryParameters

Load the parameters

Parameters

params: any

Returns

S3BinaryParameters

Overrides

CloudBinary.loadParameters

Source

packages/aws/src/services/s3binary.ts:68


log()

log(level, ...args): void

Parameters

level: WorkerLogLevel

to log

• ...args: any[]

Returns

void

Inherited from

CloudBinary.log

Source

packages/core/lib/services/service.d.ts:329


newModel()

newModel(obj): BinaryMap<any>

Based on the raw Map init a BinaryMap

Parameters

obj: any

Returns

BinaryMap<any>

Inherited from

CloudBinary.newModel

Source

packages/core/lib/services/binary.d.ts:468


off()

off(event, listener): this

Parameters

event: string | symbol

listener: (...args) => void

Returns

this

Inherited from

CloudBinary.off

Source

node_modules/@types/node/events.d.ts:61


on()

on<Key>(event, listener): this

Type the listener part

Type parameters

Key extends keyof BinaryEvents

Parameters

event: symbol | Key

listener: (evt) => void

Returns

this

Inherited from

CloudBinary.on

Source

packages/core/lib/services/service.d.ts:297


onAsync()

onAsync<Key>(event, listener, queue?): void

Listen to an event as on(...) would do except that it will be asynchronous

Type parameters

Key extends keyof BinaryEvents

Parameters

event: Key

listener: (evt) => void

queue?: string

Name of queue to use, can be undefined, queue name are used to define differents priorities

Returns

void

Inherited from

CloudBinary.onAsync

Source

packages/core/lib/services/service.d.ts:304


once()

once(event, listener): this

Parameters

event: string | symbol

listener: (...args) => void

Returns

this

Inherited from

CloudBinary.once

Source

node_modules/@types/node/events.d.ts:59


prependListener()

prependListener(event, listener): this

Parameters

event: string | symbol

listener: (...args) => void

Returns

this

Inherited from

CloudBinary.prependListener

Source

node_modules/@types/node/events.d.ts:70


prependOnceListener()

prependOnceListener(event, listener): this

Parameters

event: string | symbol

listener: (...args) => void

Returns

this

Inherited from

CloudBinary.prependOnceListener

Source

node_modules/@types/node/events.d.ts:71


putMarker()

putMarker(hash, suffix, storeName): Promise<PutObjectCommandOutput>

Parameters

hash: string

suffix: string

storeName: string

Returns

Promise<PutObjectCommandOutput>

Inherit Doc

Source

packages/aws/src/services/s3binary.ts:145


putObject()

putObject(key, body, metadatas, bucket): Promise<void>

Add an object to S3 bucket

Parameters

key: string

to add to

body: string | Blob | Buffer | ReadableStream<any>

content of the object

metadatas: Object= {}

to put along the object

bucket: string= undefined

to use

Returns

Promise<void>

Source

packages/aws/src/services/s3binary.ts:365


putRedirectUrl()

putRedirectUrl(ctx): Promise<Object>

Parameters

ctx: WebContext<any, any>

Returns

Promise<Object>

headers

headers: Object

Index signature

[key: string]: string

method

method: string

url

url: string

Overrides

CloudBinary.putRedirectUrl

Inherit Doc

Source

packages/aws/src/services/s3binary.ts:82


rawListeners()

rawListeners(event): Function[]

Parameters

event: string | symbol

Returns

Function[]

Inherited from

CloudBinary.rawListeners

Source

node_modules/@types/node/events.d.ts:66


reinit()

reinit(config): Promise<S3Binary<T>>

Parameters

config: DeepPartial<T>

new parameters for the service

Returns

Promise<S3Binary<T>>

Inherited from

CloudBinary.reinit

Source

packages/core/lib/services/service.d.ts:280


removeAllListeners()

removeAllListeners(event?): this

Parameters

event?: string | symbol

Returns

this

Inherited from

CloudBinary.removeAllListeners

Source

node_modules/@types/node/events.d.ts:62


removeListener()

removeListener(event, listener): this

Parameters

event: string | symbol

listener: (...args) => void

Returns

this

Inherited from

CloudBinary.removeListener

Source

node_modules/@types/node/events.d.ts:60


resolve()

resolve(): this

Returns

this

Inherited from

CloudBinary.resolve

Source

packages/core/lib/services/binary.d.ts:455


setMaxListeners()

setMaxListeners(n): this

Parameters

n: number

Returns

this

Inherited from

CloudBinary.setMaxListeners

Source

node_modules/@types/node/events.d.ts:63


stop()

stop(): Promise<void>

Shutdown the current service if action need to be taken

Returns

Promise<void>

Inherited from

CloudBinary.stop

Source

packages/core/lib/services/service.d.ts:188


store()

store(object, property, file): Promise<void>

Parameters

object: CoreModel

property: string

file: BinaryFile<any>

Returns

Promise<void>

Overrides

CloudBinary.store

Inherit Doc

Source

packages/aws/src/services/s3binary.ts:383


toJSON()

toJSON(): string

Prevent service to be serialized

Returns

string

Inherited from

CloudBinary.toJSON

Source

packages/core/lib/services/service.d.ts:268


toPublicJSON()

toPublicJSON(object): string

Convert an object to JSON using the Webda json filter

Parameters

object: unknown

The object to export

Returns

string

The export of the strip object ( removed all attribute with _ )

Inherited from

CloudBinary.toPublicJSON

Source

packages/core/lib/services/service.d.ts:263


toString()

toString(): string

Return service representation

Returns

string

Inherited from

CloudBinary.toString

Source

packages/core/lib/services/service.d.ts:192


uploadSuccess()

uploadSuccess(object, property, file): Promise<void>

Ensure events are sent correctly after an upload and update the BinaryFileInfo in targetted object

Parameters

object: BinaryModel<Object>

property: string

file: BinaryFileInfo

Returns

Promise<void>

Inherited from

CloudBinary.uploadSuccess

Source

packages/core/lib/services/binary.d.ts:486


listenerCount()

static listenerCount(emitter, event): number

Parameters

emitter: EventEmitter

event: string | symbol

Returns

number

Inherited from

CloudBinary.listenerCount

Deprecated

since v4.0.0

Source

node_modules/@types/node/events.d.ts:26


on()

static on(emitter, event): AsyncIterableIterator<any>

Parameters

emitter: EventEmitter

event: string

Returns

AsyncIterableIterator<any>

Inherited from

CloudBinary.on

Source

node_modules/@types/node/events.d.ts:23


once()

once(emitter, event)

static once(emitter, event): Promise<any[]>

Parameters

emitter: NodeEventTarget

event: string | symbol

Returns

Promise<any[]>

Inherited from

CloudBinary.once

Source

node_modules/@types/node/events.d.ts:21

once(emitter, event)

static once(emitter, event): Promise<any[]>

Parameters

emitter: DOMEventTarget

event: string

Returns

Promise<any[]>

Inherited from

CloudBinary.once

Source

node_modules/@types/node/events.d.ts:22


streamToBuffer()

static streamToBuffer(stream): Promise<Buffer>

Read a stream to a buffer

Parameters

stream: Readable

Returns

Promise<Buffer>

Inherited from

CloudBinary.streamToBuffer

Source

packages/core/lib/services/binary.d.ts:475