Skip to main content

S3Binary

@webda/aws


Class: S3Binary<T>

Defined in: aws/src/services/s3binary.service.ts:162

S3Binary handles the storage of binary on a S3 bucket

The structure used for now is /{hash}/data /{hash}/{attribute}{uuid} usage markers /{hash}/vproof{challenge} the proof of possession, written once the service read the bytes /{hash}/proof_{challenge} legacy proof written from a client announced value: ignored /pending/{hash}/{model}{attribute}_{uuid} a direct upload waiting for its completion

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​

T extends S3BinaryParameters = S3BinaryParameters

Implements​

Constructors​

Constructor​

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

Defined in: core/lib/services/service.d.ts:72

Service

Parameters​

name​

string

The name of the service

params​

T

The parameters block define in the configuration file

Returns​

S3Binary<T>

Inherited from​

CloudBinary<T>.constructor

Properties​

_compiledCapabilities​

protected _compiledCapabilities: Record<string, any>

Defined in: core/lib/services/iservice.d.ts:38

Capabilities detected at compile-time from @WebdaCapability-tagged interfaces.

Populated during Service.resolve by reading the service's entry in webda.module.json. Each key is a capability name (e.g., "request-filter"), and the value is an empty object {} by default. Override getCapabilities to provide capability-specific configuration or to conditionally disable capabilities.

See​

getCapabilities

Inherited from​

CloudBinary._compiledCapabilities


_lowercaseMaps​

_lowercaseMaps: any

Defined in: core/lib/services/binary.service.d.ts:746

Inherited from​

CloudBinary._lowercaseMaps


_s3​

_s3: S3

Defined in: aws/src/services/s3binary.service.ts:167


_s3Config​

protected _s3Config: any

Defined in: aws/src/services/s3binary.service.ts:171

S3 client configuration, with plain credentials


[WEBDA_EVENTS]​

[WEBDA_EVENTS]: BinaryEvents

Defined in: core/lib/services/service.d.ts:50

Set the Webda events here

Inherited from​

CloudBinary.[WEBDA_EVENTS]


hookedModels​

protected hookedModels: Set<string>

Defined in: core/lib/services/binary.service.d.ts:854

Identifiers of the models whose deletion is already followed, so a second init() does not cascade twice

Inherited from​

CloudBinary.hookedModels


logger​

protected logger: Logger

Defined in: core/lib/services/service.d.ts:59

Logger with class context

Inherited from​

CloudBinary.logger


metrics​

metrics: object

Defined in: core/lib/services/binary.service.d.ts:747

Get metrics

delete​

delete: Counter

download​

download: Counter

metadataUpdate​

metadataUpdate: Counter

upload​

upload: Counter

Inherited from​

CloudBinary.metrics


name​

readonly name: string

Defined in: core/lib/services/iservice.d.ts:18

Inherited from​

CloudBinary.name


parameters​

readonly parameters: T

Defined in: core/lib/services/iservice.d.ts:19

Inherited from​

CloudBinary.parameters


pendingDeletes​

protected pendingDeletes: Map<string, { infos: object[]; model: string; uuid: string; }>

Defined in: core/lib/services/binary.service.d.ts:843

Binaries of a deleted object, kept between the Delete (before) and Deleted (after) events of its repository

Inherited from​

CloudBinary.pendingDeletes


schemes​

readonly schemes: string[]

Defined in: aws/src/services/s3binary.service.ts:166

Schemes handled, without ':' e.g. ["s3"], ["gs", "gcs"]

Overrides​

CloudBinary.schemes


createConfiguration?​

static optional createConfiguration?: (params) => any

Defined in: core/lib/services/iservice.d.ts:23

Create configuration set by the application on load

Parameters​

params​

any

Returns​

any

Inherited from​

CloudBinary.createConfiguration


filterConfiguration?​

static optional filterConfiguration?: (params) => any

Defined in: core/lib/services/iservice.d.ts:27

Create configuration set by the application on load

Parameters​

params​

any

Returns​

any

Inherited from​

CloudBinary.filterConfiguration


Parameters​

static Parameters: typeof ServiceParameters

Defined in: core/lib/services/service.d.ts:46

Service parameters

Inherited from​

CloudBinary.Parameters


PROOF_PREFIX​

readonly static PROOF_PREFIX: "vproof_" = "vproof_"

Defined in: aws/src/services/s3binary.service.ts:663

Prefix of the proof markers written by the service from the bytes it read (vproof_<challenge>)


USAGE_PREFIX​

readonly static USAGE_PREFIX: "@" = "@"

Defined in: aws/src/services/s3binary.service.ts:678

Prefix of the usage markers naming their model: @ is no identifier character, so a marker never equals a legacy <attribute>_<uuid> one nor starts like a proof

Methods​

__clean()​

abstract __clean(): Promise<void>

Defined in: core/lib/services/service.d.ts:215

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

Returns​

Promise<void>

Inherited from​

CloudBinary.__clean


_cleanHash()​

_cleanHash(hash): Promise<void>

Defined in: aws/src/services/s3binary.service.ts:872

Delete the binary data and all its markers

Parameters​

hash​

string

the binary hash

Returns​

Promise<void>


_cleanUsage()​

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

Defined in: aws/src/services/s3binary.service.ts:902

Parameters​

hash​

string

the binary hash

uuid​

string

the object uuid

attribute​

string

the binary attribute: only the exact usage marker of (model, attribute, uuid) is removed (see usageMarker), the usages of the other objects are kept. The data is kept: the cascade removes it once unused

model​

string

the model identifier of the object

Returns​

Promise<void>

Overrides​

CloudBinary._cleanUsage


_exists()​

_exists(hash): Promise<boolean>

Defined in: aws/src/services/s3binary.service.ts:943

Check if the binary data exists

Parameters​

hash​

string

the binary hash

Returns​

Promise<boolean>

true if it exists


_get()​

_get(info): Promise<Readable>

Defined in: aws/src/services/s3binary.service.ts:829

Parameters​

info​

BinaryMap

the binary to retrieve

Returns​

Promise<Readable>

the binary content stream

Overrides​

CloudBinary._get


_getKey()​

_getKey(hash, suffix?): string

Defined in: core/lib/services/cloudbinary.d.ts:79

Return the S3 key

Parameters​

hash​

string

the hash value

suffix?​

string

the suffix to append

Returns​

string

the result string

Inherited from​

CloudBinary._getKey


_getS3()​

_getS3(hash): Promise<HeadObjectCommandOutput>

Defined in: aws/src/services/s3binary.service.ts:963

Get a head object

Parameters​

hash​

string

the binary hash

Returns​

Promise<HeadObjectCommandOutput>

the head result or undefined if not found


addListener()​

addListener<Key>(eventName, listener): this

Defined in: core/lib/events/asynceventemitter.d.ts:80

Type Parameters​

Key​

Key extends keyof BinaryEvents

Parameters​

eventName​

Key

the event name

listener​

(event) => void | Promise<void>

the event listener

Returns​

this

this for chaining

See​

EventEmitter.addListener

Inherited from​

CloudBinary.addListener


addRoute()​

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

Defined in: core/lib/services/service.d.ts:177

Add a route dynamicaly

Parameters​

url​

string

of the route can contains dynamic part like {uuid}

methods​

HttpMethodType[]

the HTTP methods

executer​

Function

Method to execute for this route

openapi?​

OpenAPIWebdaDefinition

the OpenAPI specification

override?​

boolean

whether to override existing

Returns​

void

Inherited from​

CloudBinary.addRoute


authorizeClientEvent()​

authorizeClientEvent(_event, _context): boolean

Defined in: core/lib/services/service.d.ts:153

Authorize a public event subscription

Parameters​

_event​

string

the event name

_context​

OperationContext

the execution context

Returns​

boolean

true if the condition is met

Inherited from​

CloudBinary.authorizeClientEvent


cascadeDelete()​

cascadeDelete(info, uuid, attribute, model): Promise<void>

Defined in: aws/src/services/s3binary.service.ts:929

Remove the deleted object's usage marker of the attribute, then the data and its proofs once no usage and no pending upload remain

Parameters​

info​

BinaryMap

the binary map

uuid​

string

the object uuid

attribute​

string

the binary attribute

model​

string

the model identifier of the object

Returns​

Promise<void>

Overrides​

CloudBinary.cascadeDelete


checkHash()​

protected checkHash(hash): void

Defined in: aws/src/services/s3binary.service.ts:495

Reject a hash that is not hexadecimal: it names S3 keys

Parameters​

hash​

string

the binary hash

Returns​

void


checkMap()​

protected checkMap(object, property): void

Defined in: core/lib/services/binary.service.d.ts:892

Check if a map is defined

Parameters​

object​

Model

the target object

property​

string

the property name

Returns​

void

Inherited from​

CloudBinary.checkMap


completeUpload()​

completeUpload(object, property, hash): Promise<void>

Defined in: aws/src/services/s3binary.service.ts:611

Attach a direct upload once the client declares it finished

The pending marker written by the challenge is required (404 otherwise) and the data object must exist (412 otherwise, the marker stays so the client can retry). The data must match the declared size and maxUploadSize, and its bytes the announced hash and challenge (the proof of possession, computed here from the stored bytes): otherwise 400, the marker and the unused data are removed. Then the proof of possession (server computed) and the usage marker are written and the binary is attached.

Parameters​

object​

CoreModelWithBinary

the model owning the binary

property​

string

the binary attribute

hash​

string

the hash announced in the challenge

Returns​

Promise<void>

Overrides​

CloudBinary.completeUpload


computeParameters()​

computeParameters(): void

Defined in: aws/src/services/s3binary.service.ts:243

Create the S3 client

Returns​

void

Overrides​

CloudBinary.computeParameters


delete()​

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

Defined in: core/lib/services/cloudbinary.d.ts:83

Parameters​

object​

CoreModelWithBinary

property​

string

index​

number

Returns​

Promise<void>

Inherited from​

CloudBinary.delete


deleteContent()​

deleteContent(url): Promise<void>

Defined in: aws/src/services/s3binary.service.ts:394

Delete content from S3

Parameters​

url​

string

s3://bucket/key or s3:///key

Returns​

Promise<void>

Overrides​

CloudBinary.deleteContent


deleteSuccess()​

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

Defined in: core/lib/services/binary.service.d.ts:960

Parameters​

object​

CoreModelWithBinary

the target object

property​

string

the property name

index?​

number

the index

Returns​

Promise<void>

the result

Inherited from​

CloudBinary.deleteSuccess


deleteUnusedData()​

protected deleteUnusedData(hash): Promise<void>

Defined in: aws/src/services/s3binary.service.ts:722

Delete the data of a hash no object uses and no other upload waits for, with its proofs

Parameters​

hash​

string

the binary hash

Returns​

Promise<void>


downloadTo()​

downloadTo(info, filename): Promise<void>

Defined in: core/lib/services/binary.service.d.ts:825

Download a binary to a file

Parameters​

info​

BinaryMap

The reference stored in your target object

filename​

any

the filename

Returns​

Promise<void>

Inherited from​

CloudBinary.downloadTo


emit()​

emit<Key>(event, data): Promise<void>

Defined in: core/lib/services/service.d.ts:204

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

Type Parameters​

Key​

Key extends keyof BinaryEvents

Parameters​

event​

Key

the event name

data​

BinaryEvents[Key]

the data to process

Returns​

Promise<void>

Inherited from​

CloudBinary.emit


encodeMarkerPart()​

protected encodeMarkerPart(part): string

Defined in: aws/src/services/s3binary.service.ts:507

Encode a pending marker part: injective and key-safe. Bytes outside [A-Za-z0-9.:@-] (so _, / and ~ too) become ~XX, so _ only separates parts and no % reaches the key (content urls decode it)

Parameters​

part​

string

the raw value

Returns​

string

the encoded part


exists()​

exists(Key, Bucket?): Promise<HeadObjectCommandOutput>

Defined in: aws/src/services/s3binary.service.ts:839

Check if an object exists on S3

Parameters​

Key​

string

the object key

Bucket?​

string = ...

the bucket, default to the configured one

Returns​

Promise<HeadObjectCommandOutput>

the head result or null if not found


forEachFile()​

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

Defined in: aws/src/services/s3binary.service.ts:1004

Iterate over the files of a bucket

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>


get()​

get(info): Promise<Readable>

Defined in: core/lib/services/binary.service.d.ts:817

Get a binary

Parameters​

info​

BinaryMap

The reference stored in your target object

Returns​

Promise<Readable>

the result

Emits​

'binaryGet'

Inherited from​

CloudBinary.get


getARNPolicy()​

getARNPolicy(_accountId): object

Defined in: aws/src/services/s3binary.service.ts:1082

IAM policy required by the service

Parameters​

_accountId​

string

AWS account id

Returns​

object

the policy statement

Action​

Action: string[]

Effect​

Effect: string = "Allow"

Resource​

Resource: string[]

Sid​

Sid: string


getCapabilities()​

getCapabilities(): Record<string, any>

Defined in: core/lib/services/iservice.d.ts:60

Return the capabilities of this service.

By default returns capabilities detected at compile-time from

Returns​

Record<string, any>

the result

Webda Capability-tagged​

interfaces in webda.module.json.

Override to disable capabilities based on configuration:

getCapabilities() {
const caps = super.getCapabilities();
if (!this.parameters.enabled) delete caps["request-filter"];
return caps;
}

Inherited from​

CloudBinary.getCapabilities


getClientEvents()​

getClientEvents(): string[]

Defined in: core/lib/services/service.d.ts:144

Return the events that an external system can subscribe to

Returns​

string[]

the list of results

Inherited from​

CloudBinary.getClientEvents


getCloudFormation()​

getCloudFormation(deployer): object

Defined in: aws/src/services/s3binary.service.ts:1116

CloudFormation resources for the bucket

Parameters​

deployer​

CloudFormationDeployerInfo

the deployer requesting the resources

Returns​

object

the resources

Implementation of​

CloudFormationContributor.getCloudFormation


getContent()​

getContent(url, options?): Promise<Readable>

Defined in: aws/src/services/s3binary.service.ts:255

Get content read stream from S3

Parameters​

url​

string

s3://bucket/key or s3:///key

options?​

ContentGetOptions

range options

Returns​

Promise<Readable>

Readable stream

Overrides​

CloudBinary.getContent


getContentBucket()​

getContentBucket(): string

Defined in: core/lib/services/cloudbinary.d.ts:49

Get bucket to register in ContentStorages

Returns​

string

bucket name or undefined

Inherited from​

CloudBinary.getContentBucket


getContentClient()​

protected getContentClient(endpoint?, credential?): S3

Defined in: aws/src/services/s3binary.service.ts:180

Use this service's region with the URL-selected endpoint and credential profile.

Parameters​

endpoint?​

string

optional URL-selected endpoint

credential?​

string

optional configured credential profile

Returns​

S3

the S3 client


getContentUrl()​

protected getContentUrl(key): string

Defined in: core/lib/services/cloudbinary.d.ts:55

Build :///

Parameters​

key​

string

object key

Returns​

string

content URL

Inherited from​

CloudBinary.getContentUrl


getFile()​

getFile(req): Promise<BinaryFile<{ }>>

Defined in: core/lib/services/binary.service.d.ts:966

Get file either from multipart post or raw

Parameters​

req​

IOperationContext

the request

Returns​

Promise<BinaryFile<{ }>>

the result

Inherited from​

CloudBinary.getFile


getMaxListeners()​

getMaxListeners(): number

Defined in: core/lib/events/asynceventemitter.d.ts:84

Returns​

number

Inherited from​

CloudBinary.getMaxListeners


getMetric()​

getMetric<T>(type, configuration): T

Defined in: core/lib/services/service.d.ts:138

Add service name label

Type Parameters​

T​

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

Parameters​

type​

CustomConstructor<T, [MetricConfiguration<T>]>

the type to look up

configuration​

MetricConfiguration<T>

the configuration

Returns​

T

the result

Inherited from​

CloudBinary.getMetric


getName()​

getName(): string

Defined in: core/lib/services/service.d.ts:209

Get service name

Returns​

string

the result string

Inherited from​

CloudBinary.getName


getObject()​

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

Defined in: aws/src/services/s3binary.service.ts:990

Get an object from s3 bucket

Parameters​

key​

string

to get

bucket?​

string

to retrieve from or default bucket

Returns​

Promise<Readable>

the object content stream

Deprecated​

Use getContent instead.


getOpenApiReplacements()​

getOpenApiReplacements(): any

Defined in: core/lib/services/service.d.ts:182

Return variables for replacement in openapi

Returns​

any

the result

Inherited from​

CloudBinary.getOpenApiReplacements


getOperationId()​

getOperationId(id): string

Defined in: core/lib/services/service.d.ts:167

If undefined is returned it cancel the operation registration

Parameters​

id​

string

the identifier

Returns​

string

the result

Inherited from​

CloudBinary.getOperationId


getOperationName()​

protected getOperationName(): string

Defined in: core/lib/services/binary.service.d.ts:971

Return the name of the service for OpenAPI

Returns​

string

the result string

Inherited from​

CloudBinary.getOperationName


getParameters()​

getParameters(): T

Defined in: core/lib/services/service.d.ts:82

Get the service parameters

Returns​

T

the result

Inherited from​

CloudBinary.getParameters


getPendingKey()​

protected getPendingKey(object, property, hash): string

Defined in: aws/src/services/s3binary.service.ts:524

Key of the pending upload of an object attribute: <prefix>/_pending/<hash>/<model>_<attribute>_<uuid>, each part encoded so that _ only separates parts

Parameters​

object​

CoreModel

the model owning the binary

property​

string

the binary attribute

hash​

string

the binary hash (hexadecimal)

Returns​

string

the key


getPendingUpload()​

protected getPendingUpload(key): Promise<PendingUpload>

Defined in: aws/src/services/s3binary.service.ts:560

Read a pending upload marker

Parameters​

key​

string

the marker key

Returns​

Promise<PendingUpload>

its information, undefined when absent, {} when unreadable


getRedirectUrlFromObject()​

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

Defined in: core/lib/services/cloudbinary.d.ts:72

Get a UrlFromObject

Parameters​

binaryMap​

any

the binary map definition

context​

any

the execution context

expires?​

number

the expiration time

Returns​

Promise<string>

the result

Inherited from​

CloudBinary.getRedirectUrlFromObject


getRepository()​

protected getRepository(model): any

Defined in: core/lib/services/binary.service.d.ts:875

Get the event emitting repository of a model

Parameters​

model​

any

the model class

Returns​

any

the repository

Inherited from​

CloudBinary.getRepository


getService()​

getService<T>(name): ServicesMap[T]

Defined in: core/lib/services/service.d.ts:131

Get a service by name

Type Parameters​

T​

T extends keyof ServicesMap

Parameters​

name​

T

the name to use

Returns​

ServicesMap[T]

the result map

Deprecated​

Use useService, might reconsider

Inherited from​

CloudBinary.getService


getSignedUrl()​

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

Defined in: aws/src/services/s3binary.service.ts:794

Return a signed url to an object

Parameters​

key​

string

to the object

action?​

"getObject" | "putObject" = "getObject"

to perform

params?​

any = {}

additional command parameters

Returns​

Promise<string>

the signed url


getSignedUrlFromMap()​

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

Defined in: aws/src/services/s3binary.service.ts:814

Parameters​

binaryMap​

BinaryMap

the binary to download

expire​

number

url validity in seconds

_context​

OperationContext

the operation context

Returns​

Promise<string>

the signed url

Overrides​

CloudBinary.getSignedUrlFromMap


getState()​

getState(): ServiceStates

Defined in: core/lib/services/service.d.ts:55

Get the current state

Returns​

ServiceStates

the result

Inherited from​

CloudBinary.getState


getStoredValue()​

protected getStoredValue(object, property): Promise<any>

Defined in: core/lib/services/binary.service.d.ts:932

The attribute value as stored: the object is re-loaded from its repository so a link made by a concurrent request (another instance of the same object) is seen. Objects without a stored copy keep their own value.

Parameters​

object​

CoreModelWithBinary

the target object

property​

string

the property name

Returns​

Promise<any>

the attribute value

Inherited from​

CloudBinary.getStoredValue


getUrl()​

getUrl(url, _methods): string

Defined in: core/lib/services/service.d.ts:161

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


getUsageCount()​

getUsageCount(hash): Promise<number>

Defined in: aws/src/services/s3binary.service.ts:858

Parameters​

hash​

string

the binary hash

Returns​

Promise<number>

the number of objects using the binary

Overrides​

CloudBinary.getUsageCount


handleBinary()​

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

Defined in: core/lib/services/binary.service.d.ts:772

Define if binary is managed by the store

Parameters​

modelName​

string

the model name

attribute​

string

the attribute name

Returns​

-1 | 0 | 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


hashStoredData()​

protected hashStoredData(hash): Promise<{ challenge: string; hash: string; }>

Defined in: aws/src/services/s3binary.service.ts:586

Hash the stored data the way clients do: md5 of the bytes, and md5 of "WEBDA" + the bytes (the challenge)

Parameters​

hash​

string

the binary hash

Returns​

Promise<{ challenge: string; hash: string; }>

the computed hash and challenge


headContent()​

headContent(url): Promise<ContentInfo>

Defined in: aws/src/services/s3binary.service.ts:366

Head content metadata from S3

Parameters​

url​

string

s3://bucket/key or s3:///key

Returns​

Promise<ContentInfo>

ContentInfo or undefined if not found

Overrides​

CloudBinary.headContent


hookDelete()​

protected hookDelete(model, attributes): void

Defined in: core/lib/services/binary.service.d.ts:884

Cascade the deletion of a model to its binaries

Delete runs before the repository deletion: the object is loaded and its binaries are kept aside. Deleted only fires once the deletion succeeded, so a failed delete leaves the binaries untouched.

Parameters​

model​

any

the model class

attributes​

string[]

the candidate behavior attributes

Returns​

void

Inherited from​

CloudBinary.hookDelete


init()​

init(): Promise<S3Binary<T>>

Defined in: aws/src/services/s3binary.service.ts:214

Start sweeping the stale pending uploads every pendingTimeout / 4

Returns​

Promise<S3Binary<T>>

this

Overrides​

CloudBinary.init


initMetrics()​

initMetrics(): void

Defined in: core/lib/services/binary.service.d.ts:756

Returns​

void

Inherited from​

CloudBinary.initMetrics


initOperations()​

initOperations(): void

Defined in: core/lib/services/service.d.ts:186

Init the operations from

Returns​

void

Operation​

decorators on this service

Inherited from​

CloudBinary.initOperations


isCollection()​

protected isCollection(object, property): boolean

Defined in: core/lib/services/binary.service.d.ts:904

Whether the binary attribute is a collection (BinariesImpl or a subclass) rather than a single Binary

Models are hydrated by the compiled __hydrateBehaviors (store deserialization, load, patch), which always instantiates the behavior class, even for an unset attribute: instanceof BinariesImpl therefore covers subclasses. The relation id comparison is the fallback for objects that were never hydrated.

Parameters​

object​

CoreModelWithBinary

the target object

property​

string

the property name

Returns​

boolean

true if the attribute holds several binaries

Inherited from​

CloudBinary.isCollection


isLinked()​

protected isLinked(object, property, hash, value?): boolean

Defined in: core/lib/services/binary.service.d.ts:924

Whether the hash is already linked to the object attribute (a collection item or the single binary)

Parameters​

object​

CoreModelWithBinary

the target object

property​

string

the property name

hash​

string

the binary hash

value?​

any

the attribute value to check, default to the object's

Returns​

boolean

true if linked

Inherited from​

CloudBinary.isLinked


isUsageMarker()​

protected isUsageMarker(key): boolean

Defined in: aws/src/services/s3binary.service.ts:708

Whether a key under <hash>/ is a usage marker: not the data, nor a proof (verified or legacy)

Parameters​

key​

string

the object key

Returns​

boolean

true for a usage marker


legacyUsageMarker()​

protected legacyUsageMarker(attribute, uuid): string

Defined in: aws/src/services/s3binary.service.ts:699

Name of the usage markers written before the model was part of the name: <attribute>_<uuid>, the model only in the x-amz-meta-store metadata. Still counted as usages, removed only for their own model

Parameters​

attribute​

string

the binary attribute

uuid​

string

the object uuid

Returns​

string

the legacy marker name


listeners()​

listeners(eventName): Function[]

Defined in: core/lib/events/asynceventemitter.d.ts:139

Get all listeners for an event

Parameters​

eventName​

keyof BinaryEvents

the event name

Returns​

Function[]

the list of results

Inherited from​

CloudBinary.listeners


loadCapabilities()​

protected loadCapabilities(): void

Defined in: core/lib/services/service.d.ts:120

Load capabilities from webda.module.json metadata into _compiledCapabilities.

Called during resolve after dependency injection. Reads the service's type name from parameters, looks it up in the application's module metadata (moddas or beans section), and populates _compiledCapabilities with an empty object for each declared capability name.

Fails silently if the application is not available (e.g., in unit tests where services are instantiated without a full application context).

Returns​

void

Example​

// If webda.module.json contains:
// { "moddas": { "MyApp/HawkService": { "capabilities": ["request-filter", "cors-filter"] } } }
// Then after resolve(), this.getCapabilities() returns:
// { "request-filter": {}, "cors-filter": {} }

See​

getCapabilities

Inherited from​

CloudBinary.loadCapabilities


log()​

log(level, ...args): void

Defined in: core/lib/services/service.d.ts:226

Parameters​

level​

WorkerLogLevel

to log

args​

...any[]

additional arguments

Returns​

void

Inherited from​

CloudBinary.log


newModel()​

newModel(obj): BinaryMap

Defined in: core/lib/services/binary.service.d.ts:832

Based on the raw Map init a BinaryMap

Parameters​

obj​

any

the target object

Returns​

BinaryMap

the result map

Inherited from​

CloudBinary.newModel


off()​

off<Key>(eventName, listener): this

Defined in: core/lib/events/asynceventemitter.d.ts:116

Type Parameters​

Key​

Key extends keyof BinaryEvents

Parameters​

eventName​

Key

the event name

listener​

(event) => void

the event listener

Returns​

this

this for chaining

See​

EventEmitter.off

Inherited from​

CloudBinary.off


on()​

on<Key>(eventName, listener): this

Defined in: core/lib/events/asynceventemitter.d.ts:102

Type Parameters​

Key​

Key extends keyof BinaryEvents

Parameters​

eventName​

Key

the event name

listener​

(event) => void

the event listener

Returns​

this

this for chaining

See​

EventEmitter.once

Inherited from​

CloudBinary.on


once()​

once<Key>(eventName, listener): this

Defined in: core/lib/events/asynceventemitter.d.ts:95

Type Parameters​

Key​

Key extends keyof BinaryEvents

Parameters​

eventName​

Key

the event name

listener​

(event) => void

the event listener

Returns​

this

this for chaining

See​

EventEmitter.once

Inherited from​

CloudBinary.once


ownsAttribute()​

protected ownsAttribute(model, attribute): boolean

Defined in: core/lib/services/binary.service.d.ts:869

Whether this service is the one storing the binaries of a model attribute

Parameters​

model​

any

the model class

attribute​

string

the attribute name

Returns​

boolean

true if owned

Inherited from​

CloudBinary.ownsAttribute


proofMarker()​

protected proofMarker(challenge): string

Defined in: aws/src/services/s3binary.service.ts:670

Name of the proof marker of a challenge computed by the service

Parameters​

challenge​

string

the server computed challenge

Returns​

string

the marker name


putContent()​

putContent(url, body, options?): Promise<ContentInfo>

Defined in: aws/src/services/s3binary.service.ts:289

Put content to S3 using streaming multipart Upload

Parameters​

url​

string

s3://bucket/key or s3:///key

body​

ContentBody

readable stream, buffer, or string

options?​

ContentPutOptions

write options

Returns​

Promise<ContentInfo>

ContentInfo

Overrides​

CloudBinary.putContent


putMarker()​

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

Defined in: aws/src/services/s3binary.service.ts:775

Put an empty marker object next to the binary data

Parameters​

hash​

string

the binary hash

suffix​

string

the marker name

storeName​

string

the model identifier using the binary

Returns​

Promise<PutObjectCommandOutput>

the putObject result


putObject()​

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

Defined in: aws/src/services/s3binary.service.ts:1037

Add an object to S3 bucket

Parameters​

key​

string

to add to

body​

string | Buffer<ArrayBufferLike> | Blob | ReadableStream<any>

content of the object

metadatas?​

{ }

to put along the object

bucket?​

string = ...

to use

Returns​

Promise<ContentInfo>

Content info

Deprecated​

Use putContent instead.


putPendingMarker()​

protected putPendingMarker(object, property, body): Promise<void>

Defined in: aws/src/services/s3binary.service.ts:538

Record a direct upload waiting for its completion: the announced information is the marker's JSON body, server side only (the challenge is never persisted on the object nor returned to clients)

Parameters​

object​

CoreModel

the model owning the binary

property​

string

the binary attribute

body​

BinaryFileInfo

the announced binary information

Returns​

Promise<void>


putRedirectUrl()​

putRedirectUrl(object, property, body?, context?): Promise<{ headers: {[key: string]: string; }; method: string; url: string; }>

Defined in: aws/src/services/s3binary.service.ts:412

Return a signed PUT url if the binary is not yet stored

Parameters​

object​

CoreModel

the model owning the binary

property​

string

the binary attribute

body?​

BinaryFileInfo

the binary information (hash and challenge)

context?​

OperationContext<BinaryFileInfo<{ }>>

the operation context

Returns​

Promise<{ headers: {[key: string]: string; }; method: string; url: string; }>

the url to upload to, or undefined if the binary is already stored

Overrides​

CloudBinary.putRedirectUrl


removeAllListeners()​

removeAllListeners<Key>(eventName?): this

Defined in: core/lib/events/asynceventemitter.d.ts:122

Type Parameters​

Key​

Key extends keyof BinaryEvents

Parameters​

eventName?​

Key

the event name

Returns​

this

this for chaining

See​

EventEmitter.removeAllListeners

Inherited from​

CloudBinary.removeAllListeners


removeListener()​

removeListener<Key>(eventName, listener): this

Defined in: core/lib/events/asynceventemitter.d.ts:109

Type Parameters​

Key​

Key extends keyof BinaryEvents

Parameters​

eventName​

Key

the event name

listener​

(event) => void

the event listener

Returns​

this

this for chaining

See​

EventEmitter.removeListener

Inherited from​

CloudBinary.removeListener


resolve()​

resolve(): this

Defined in: core/lib/services/service.d.ts:98

Resolve parameters and load metadata. @Route-declared routes are scanned and registered by Router.discoverRoutes(services) from Core.init() once every service has resolved — nothing to do per-service here.

Returns​

this

the result

Inherited from​

CloudBinary.resolve


setMaxListeners()​

setMaxListeners(n): this

Defined in: core/lib/events/asynceventemitter.d.ts:88

Parameters​

n​

number

Returns​

this

Inherited from​

CloudBinary.setMaxListeners


stop()​

stop(): Promise<void>

Defined in: aws/src/services/s3binary.service.ts:229

Release URL-selected clients when the service stops.

Returns​

Promise<void>

Overrides​

CloudBinary.stop


store()​

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

Defined in: aws/src/services/s3binary.service.ts:1054

Parameters​

object​

CoreModel

the model owning the binary

property​

string

the binary attribute

file​

BinaryFile

the binary to store

Returns​

Promise<void>

Overrides​

CloudBinary.store


sweepPending()​

sweepPending(now?): Promise<number>

Defined in: aws/src/services/s3binary.service.ts:742

Remove the pending uploads older than pendingTimeout, and their data when no object uses it

Parameters​

now?​

number = ...

the current time in ms

Returns​

Promise<number>

the number of pending uploads removed


toJSON()​

toJSON(): string

Defined in: core/lib/services/service.d.ts:191

Prevent service to be serialized

Returns​

string

the result

Inherited from​

CloudBinary.toJSON


toString()​

toString(): string

Defined in: core/lib/services/service.d.ts:91

Return service representation

Returns​

string

the result

Inherited from​

CloudBinary.toString


uploadSuccess()​

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

Defined in: core/lib/services/binary.service.d.ts:939

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

Parameters​

object​

CoreModelWithBinary

the target object

property​

string

the property name

fileInfo​

BinaryFileInfo<{ }> | { toBinaryFileInfo: () => BinaryFileInfo; }

the file information

Returns​

Promise<void>

Inherited from​

CloudBinary.uploadSuccess


usageMarker()​

protected usageMarker(model, attribute, uuid): string

Defined in: aws/src/services/s3binary.service.ts:688

Name of the usage marker of an object attribute under <hash>/: @<model>_<attribute>_<uuid>, each part encoded so that _ only separates parts. Written on attach and removed on delete, the only place the name is built

Parameters​

model​

string

the model identifier of the object

attribute​

string

the binary attribute

uuid​

string

the object uuid

Returns​

string

the marker name


verifiedHashes()​

protected verifiedHashes(file): Promise<{ challenge: string; hash: string; }>

Defined in: core/lib/services/binary.service.d.ts:912

Hashes of a file to store, computed from its bytes: a hash or challenge set on the file is never trusted

A preset hash that differs from the content is rejected; the file then carries the computed values

Parameters​

file​

BinaryFile

the file to store

Returns​

Promise<{ challenge: string; hash: string; }>

the computed hash and challenge

Inherited from​

CloudBinary.verifiedHashes


verifyMapAndStore()​

protected verifyMapAndStore(ctx): IStore

Defined in: core/lib/services/binary.service.d.ts:977

Based on the request parameter verify it match a known mapping

Parameters​

ctx​

IOperationContext

the operation context

Returns​

IStore

the result

Inherited from​

CloudBinary.verifyMapAndStore


streamToBuffer()​

static streamToBuffer(stream): Promise<Buffer<ArrayBufferLike>>

Defined in: core/lib/services/binary.service.d.ts:839

Read a stream to a buffer

Parameters​

stream​

Readable

the stream

Returns​

Promise<Buffer<ArrayBufferLike>>

the result

Inherited from​

CloudBinary.streamToBuffer