Skip to main content
Version: 2.13

File

File is the main class used to create business objects with a binary/string data content. It is a Data Type so can be extended and associated to a data source.

Extends​

Constructors​

Constructor​

new File(): File;

Returns​

File

Inherited from​

CloudObject.constructor

Properties​

containsRel​

static containsRel: Relation<CloudObject, CloudObject>;

Relation between a container (a CloudObject) that has children (other CloudObjects)

For example, from a folder to the contained elements or from a function to the elements needed for that function to run.

Inherited from​

CloudObject.containsRel


creationDateProp​

static creationDateProp: Property<Date>;

extendedByRel​

static extendedByRel: Relation<CloudObject, CloudObject>;

Inverse relation of extendRel

Inherited from​

CloudObject.extendedByRel


extendRel​

static extendRel: Relation<CloudObject, CloudObject>;

Model CloudObjects can inherit relations and properties from another CloudObject model to mimic their behaviour.

Relation from a model to the CloudObject model it extends. A --extendRel-> B A inherits B's properties and relations.

Inherited from​

CloudObject.extendRel


fileNameProp​

static fileNameProp: Property<string>;

instancesRel​

static instancesRel: Relation<CloudObject, CloudObject>;

Inverse relation of modelRel between a model and its instances Equivalent to modelRel.getInverse()

Inherited from​

CloudObject.instancesRel


mimeTypeProp​

static mimeTypeProp: Property<string>;

modelRel​

static modelRel: Relation<CloudObject, CloudObject>;

Relation between a CloudObjectand its model instance --modelRel-> model

Inherited from​

CloudObject.modelRel


modificationDateProp​

static modificationDateProp: Property<Date>;

nameProp​

static nameProp: Property<string>;

Deprecated​

because conflict with CloudObject.nameProp. Use File.fileNameProp instead.

Overrides​

CloudObject.nameProp


propertyRel​

static propertyRel: Relation<CloudObject, PropertyModel>;

Relation between a model and the properties it defines.

Inherited from​

CloudObject.propertyRel


urlProp​

static urlProp: Property<string>;

Methods​

asInstance()​

static asInstance<T>(this): T;

Get this CloudObject class as a CloudObject instance.

Type Parameters​

Type Parameter
T

Parameters​

ParameterType
thisClass<T>

Returns​

T

the current data type class as a CloudObject instance.

Inherited from​

CloudObject.asInstance


createFromContent()​

static createFromContent(
transaction,
name,
content,
mimeType?,
source?,
tag?): string;

Parameters​

ParameterTypeDescription
transactionTransactiontransaction in which to create the file
namestringfilename
contentUint8Array | ArrayBufferbyte content of the file
mimeType?stringoptional mime type of the file
source?stringoptional source where file will be stored ({PredefinedDataSource} or DBConnector tag)
tag?stringoptional tag for the file

Returns​

string

tag string of the file

Deprecated​

Please use File.setContent Create a File from its content


createFromURL()​

static createFromURL(
transaction,
name,
url,
mimeType?,
source?,
tag?): string;

Parameters​

ParameterTypeDescription
transactionTransactiontransaction in which to create the file
namestringfilename
urlstringurl to retrieve content from
mimeType?stringoptional mime type of the file
source?stringoptional source where file will be stored ({PredefinedDataSource} or DBConnector tag)
tag?stringoptional tag for the file

Returns​

string

tag string of the file

Deprecated​

Please use File.setURLContent Create a File from a specified URL


createWith()​

static createWith<T>(
this,
properties,
model?,
source?): T;

Create an instance of the specified data type (or model) in the local datacloud (not persisted) with the specified property values.

If the model is not specified, it uses this DataType.

Type Parameters​

Type Parameter
T

Parameters​

ParameterTypeDescription
thisClass<T>-
propertiesMap<InstanceOrTag, any>mappings of (propertyTag -> propertyValue)
model?InstanceOrTagtag of the model of the CloudObject you want to create.
source?string

Returns​

T

newly created CloudObject

Inherited from​

CloudObject.createWith


exists()​

static exists(tag): boolean;

Checks whether a CloudObject exists or not.

Parameters​

ParameterTypeDescription
tagInstanceOrTagtag of the CloudObject

Returns​

boolean

true if tag is valid and references a CloudObject.

Static​

Inherited from​

CloudObject.exists


get()​

static get<T>(tag): T;

Get the CloudObject whose tag is specified.

This only works if the CloudObject is already present in the local datacloud cache. (NB: you can use a Query to retrieve a distant CloudObject)

Type Parameters​

Type Parameter
T extends CloudObject

Parameters​

ParameterTypeDescription
tagInstanceOrTagtag of the CloudObject

Returns​

T

CloudObject specified by the tag

Static​

Inherited from​

CloudObject.get


getProperties()​

static getProperties(): Property<any>[];

The attributes of a CloudObject are called properties. Properties can be of different types, e.g. Property<string>, Property<number>, Property<Date>.

If a Person CloudObject has an age property, all the instances of Person can access the age property using the same tag, the tag of the age property. This method returns all properties defined by the Data Type associated to this class.

Returns​

Property<any>[]

All properties defined for a data type

Inherited from​

CloudObject.getProperties


getRelations()​

static getRelations<O, D>(this): (
| Relation<O, D>
| Relation<D, O>)[];

Return all the relations whose origin OR destination is the CloudObject associated to this class.

Type Parameters​

Type Parameter
O extends CloudObject
D extends CloudObject

Parameters​

ParameterType
thisClass<O>

Returns​

( | Relation<O, D> | Relation<D, O>)[]

All relations defined on the current data type. It can be the destination or the origin of the relations.

Inherited from​

CloudObject.getRelations


instancesOf()​

static instancesOf<T>(model): Query<T, never>;

Return a query starting from all instances of this Data Type.

Type Parameters​

Type Parameter
T extends CloudObject

Parameters​

ParameterTypeDescription
model| InstanceOrTag | Class<T>data type to get instances of

Returns​

Query<T, never>

A query starting from the instances of the specified model.

Inherited from​

CloudObject.instancesOf


markObsolete()​

static markObsolete(...tags): void;

Mark the specified instances as obsolete in cache database: the instances won't exist anymore in the local cache. It does not delete the instances from the remote data store and they can still be retrieved using a Query. Warning: this is only for experimented users: only use this method if you know what you are doing.

Parameters​

ParameterTypeDescription
...tagsInstanceOrTag[]

Returns​

void

Static​

Inherited from​

CloudObject.markObsolete


setContent()​

static setContent(
transaction,
file,
name,
content,
mimeType?): void;

Set the binary content of a specified file

Parameters​

ParameterTypeDescription
transactionTransactiontransaction in which to create the file
fileInstanceOrTagtag of the file
namestringfile name
contentUint8Array | ArrayBufferbyte content of the file
mimeType?stringoptional mime type of the file

Returns​

void


setURLContent()​

static setURLContent(
transaction,
file,
name,
url,
mimeType?): void;

Set the content of a File from a specified URL

Parameters​

ParameterTypeDescription
transactionTransactiontransaction in which to create the file
fileInstanceOrTagtag of the file
namestringfilename
urlstringurl to retrieve content from
mimeType?stringoptional mime type of the file

Returns​

void


equals()​

equals(object): boolean;

Compare this CloudObject and the given one and return whether they are identical or not.

Parameters​

ParameterTypeDescription
objectanythe object to compare

Returns​

boolean

true if the specified object is the same CloudObject

Inherited from​

CloudObject.equals


follow()​

follow<D>(relation): Query<D, never>;

Start a query from this instance and follow the relation given as argument. The query starts from this single instance, and follows a relation to an arbitrary number of destination instances. See Query.follow(relation)

The following are equivalent:

myCloudObject.follow(relation);
myCloudObject.query().follow(relation);

Type Parameters​

Type Parameter
D extends CloudObject

Parameters​

ParameterTypeDescription
relationRelation<File, D>the relation to follow from the starting instance (this)

Returns​

Query<D, never>

query starting from this and following the relation relation as first step of the query

Inherited from​

CloudObject.follow


followSingle()​

followSingle<D>(relation): QuerySingle<D>;

Start a querySingle from this instance that follows 0..1 relations

The query starts from this instance, and follow the relation to a single destination instance. It is equivalent to QuerySingle.from(this).follow(relation).

Type Parameters​

Type Parameter
D extends CloudObject

Parameters​

ParameterTypeDescription
relationRelation<File, D>to follow from this starting instance

Returns​

QuerySingle<D>

a query following 0-1 relations

Inherited from​

CloudObject.followSingle


get()​

get<T>(property): T;

Get the current value of the specified property for this CloudObject instance

Type Parameters​

Type Parameter
T

Parameters​

ParameterTypeDescription
property| InstanceOrTag | Property<T>property or property's tag

Returns​

T

property value

Inherited from​

CloudObject.get


getContentAsBinary()​

Call Signature​

getContentAsBinary(onSuccess, onFailure?): any;

Gets the file content as an ArrayBuffer.

Parameters​
ParameterTypeDescription
onSuccess(content) => void(deprecated) callback to execute when byte content has been retrieved successfully
onFailure?(errMsg) => void(deprecated) callback to execute when content retrieval has failed
Returns​

any

Deprecated​

consider using the new getContentAsBinary method returning a Promise instead

Call Signature​

getContentAsBinary(): Promise<ArrayBuffer>;

Gets the file content as an ArrayBuffer.

Returns​

Promise<ArrayBuffer>

promise resolving with the content as a byte array


getContentAsString()​

Call Signature​

getContentAsString(onSuccess, onFailure?): any;

Get the content of this file and returns it as an UTF-8 string. Note: this method should be used only when the file is a text file.

Parameters​
ParameterTypeDescription
onSuccess(content) => void(deprecated) callback to execute when string content has been retrieved successfully
onFailure?(errMsg) => void(deprecated) callback to execute when content retrieval has failed
Returns​

any

Deprecated​

consider using the new getContentAsString method returning a Promise instead

Call Signature​

getContentAsString(): Promise<string>;

Get the content of this file and returns it as an UTF-8 string. Note: this method should be used only when the file is a text file.

Returns​

Promise<string>

promise resolving with the content as a string


getContentUrl()​

Call Signature​

getContentUrl(onSuccess, onFailure?): any;

Gets the URL that gives direct access to the file content:

  • For files that are external to Olympe, gives the normal URL
  • For the files stored by Olympe, provides a dataURL, with the content embedded in Base64
Parameters​
ParameterTypeDescription
onSuccess(content) => void(deprecated) callback to execute when content has been retrieved successfully
onFailure?() => void(deprecated) callback to execute when content retrieval has failed
Returns​

any

Deprecated​

consider using the new getContentUrl method returning a Promise instead

Call Signature​

getContentUrl(): Promise<string>;

Gets the URL that gives direct access to the file content:

  • For files that are external to Olympe, gives the normal URL
  • For the files stored by Olympe, provides a dataURL, with the content embedded in Base64
Returns​

Promise<string>

promise resolving with the content as a string


getModel()​

getModel(): CloudObject;

Every CloudObject has a model which defines relations and properties its instances may have.

Returns​

CloudObject

the model of this CloudObject instance as a CloudObject instance

Inherited from​

CloudObject.getModel


getModelTag()​

getModelTag(): string;

Every CloudObject has a model which defines relations and properties its instances may have.

Returns​

string

the tag of the model of this CloudObject instance

Inherited from​

CloudObject.getModelTag


getSource()​

getSource(): string;

Return the source id that owns this cloud object.

Returns​

string

Inherited from​

CloudObject.getSource


getTag()​

getTag(): string;

Every CloudObject has a unique tag.

Returns​

string

tag of the CloudObject

Inherited from​

CloudObject.getTag


isPersisted()​

isPersisted(): boolean;

Return the persistence state of this instance.

CloudObjects can either be volatile, and only live in the local cache. In this case, the CloudObject instance is not persisted. If a CloudObjectis persisted, it is stored in an external data store. This means that the instance can be accessible through other Olympe VMs in the same environment.

Returns​

boolean

a boolean indicating if this object is persisted in a non-volatile way.

Inherited from​

CloudObject.isPersisted


name()​

name(): string;

Every CloudObject can define a value for its nameProperty. This method returns the current value of that property for this instance.

Returns​

string

the value of the name property of this

Inherited from​

CloudObject.name


observe()​

observe<T>(
context,
property,
waitForValue?): Observable<T>;

Get an observable to the current value of the specified property for this CloudObject instance.

The observable gets the new value each time the property gets updated in the datacloud. The observable gets completed automatically once the specified context is cleared. If waitForValue is set to FALSE (TRUE by default), the first value received by the observable is null if there is no value at call time.

Type Parameters​

Type Parameter
T

Parameters​

ParameterTypeDescription
contextContextcontext to which the Observable is attached
property| InstanceOrTag | Property<T>property or property's tag to observe
waitForValue?booleanwhether the observable wait for a first value to get a value. (Default = true)

Returns​

Observable<T>

Observable of property values

Inherited from​

CloudObject.observe


observeProperties()​

observeProperties<T>(context): Observable<[Property<T>, T]>;

Get an observable to pair [property, value] for this CloudObject instance.

The observable gets the new value each time any property gets updated in the datacloud. The observable gets completed automatically once the specified context is cleared.

Type Parameters​

Type Parameter
T

Parameters​

ParameterTypeDescription
contextContextContext to which the Observable will be attached

Returns​

Observable<[Property<T>, T]>

Observable of property values

Inherited from​

CloudObject.observeProperties


query()​

query(): Query<File, never>;

Create and return a query starting from this instance

Returns​

Query<File, never>

a query starting at this CloudObject instance

Inherited from​

CloudObject.query


saveAs()​

saveAs(name): void;

Save this file with specified name

Parameters​

ParameterTypeDescription
namestringfilename

Returns​

void


toJSON()​

toJSON(): Object;

Create a Javascript object from this CloudObject current state, including its tag and property values. It provides the same result as toObject called with nameAsKey = true and inheritedProperties = false.

Returns​

Object

Inherited from​

CloudObject.toJSON


toObject()​

toObject(namesAsKey?, inheritedProperties?): Object;

Create a Javascript object from this CloudObject current state.

Parameters​

ParameterTypeDescription
namesAsKey?booleanIf true, use the property name instead of the property tag as keys of the generated object.
inheritedProperties?booleanIf false, do not including inherited property. By default, it includes them.

Returns​

Object

Inherited from​

CloudObject.toObject