Home Reference Source
import {FileStore} from './core/files.js'
public class | source

FileStore

The FileStore class is used to find, save, update, remove, count and group files.

Method Summary

Public Methods
public

download(name: string, options: Object): Promise<string>

Download a file.

public

Download a file using a url.

public

find(query: Query, options: Object): Promise<Object[]>

Finds all files.

public

findById(id: *, options: *): *

public

removeById(id: *, options: {}): *

public

stream(name: string, options: Object): Promise

Stream a file.

public

upload(file: Blob | string, metadata: Object, options: Object): Promise<File>

Upload a file.

Public Methods

public download(name: string, options: Object): Promise<string> source

Download a file.

Params:

NameTypeAttributeDescription
name string
  • optional

_id of the file to download.

options Object
  • optional

Options

options.tls boolean
  • optional
  • default: true

By default, all requests to retrieve files are made with https. By setting this flag to false, files are retrieved over unsecure http connections.

options.ttl number
  • optional

Specify a time to live for the _downloadURL to limit the amount of time the download url is valid.

Return:

Promise<string>

A string representing the file.

public downloadByUrl(url: string, options: Object): Promise<string> source

Download a file using a url.

Params:

NameTypeAttributeDescription
url string

File download url

options Object
  • optional

Options

Return:

Promise<string>

File content.

public find(query: Query, options: Object): Promise<Object[]> source

Finds all files. A query can be optionally provided to return a subset of all the files for your application or omitted to return all the files. The number of files returned will adhere to the limits specified at http://devcenter.kinvey.com/rest/guides/datastore#queryrestrictions. A promise will be returned that will be resolved with the files or rejected with an error.

Params:

NameTypeAttributeDescription
query Query
  • optional

Query used to filter result.

options Object
  • optional

Options

options.tls boolean
  • optional
  • default: true

By default, all requests to retrieve files are made with https. By setting this flag to false, files are retrieved over unsecure http connections.

options.ttl number
  • optional

Specify a time to live for the _downloadURL to limit the amount of time the download url is valid.

options.download boolean
  • optional
  • default: false

Download the files

Return:

Promise<Object[]>

An array of Kinvey file objects.

public findById(id: *, options: *): * source

Params:

NameTypeAttributeDescription
id *
options *

Return:

*

public removeById(id: *, options: {}): * source

Params:

NameTypeAttributeDescription
id *
options {}
  • optional
  • default: {}

Return:

*

public stream(name: string, options: Object): Promise source

Stream a file. A promise will be returned that will be resolved with the file or rejected with an error.

Params:

NameTypeAttributeDescription
name string

File name

options Object
  • optional

Options

options.tls Boolean
  • optional

Use Transport Layer Security

options.ttl Number
  • optional

Time To Live (in seconds)

options.dataPolicy DataPolicy
  • optional
  • default: DataPolicy.NetworkFirst

Data policy

options.authType AuthType
  • optional
  • default: AuthType.Default

Auth type

Return:

Promise

Promise

Example:

var files = new Kinvey.Files();
files.stream('BostonTeaParty.png', {
  tls: true, // Use transport layer security
  ttl: 60 * 60 * 24, // 1 day in seconds
}).then(function(file) {
  ...
}).catch(function(err) {
  ...
});

public upload(file: Blob | string, metadata: Object, options: Object): Promise<File> source

Upload a file.

Params:

NameTypeAttributeDescription
file Blob | string

File content

metadata Object
  • optional
  • default: {}

File metadata

options Object
  • optional
  • default: {}

Options

Return:

Promise<File>

A file entity.