Constructor
new File(fileOptions)
Creates a new file object which represents a file at the given id. Data which is provided to the constructor will
be uploaded by invoking upload()
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fileOptions |
object | string | The fileOptions used to create a new file object, or just the id of the file |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Properties
|
- Source:
Members
(readonly) acl :Acl
The current file acl, only accessible after fetching the metadata or downloading/uploading/providing the file
Type:
- Source:
(readonly) bucket :string
Type:
- string
- Source:
(readonly, nullable) createdAt :Date
The creation date of the file, only accessible after fetching the metadata
or downloading/uploading/providing the eTag
Type:
- Date
- Source:
(readonly) eTag :string
The eTag of the file, only accessible after fetching the metadata or downloading/uploading/providing the file
Type:
- string
- Source:
(readonly) headers :Object.<string, string>
The custom headers of the file, only accessible after fetching the metadata or downloading/uploading/providing
the file
Type:
- Object.<string, string>
- Source:
(readonly) id :string
The complete id of the file, including folder and name
Type:
- string
- Source:
(readonly) isFolder :boolean
Specifies whether this file is a folder.
Type:
- boolean
- Source:
(readonly) isMetadataLoaded :boolean
Indicates if the metadata are loaded.
Type:
- boolean
- Source:
(readonly) key :string
Type:
- string
- Source:
(readonly, nullable) lastModified :Date
The last modified date of the file, only accessible after fetching the metadata
or downloading/uploading/providing the eTag
Type:
- Date
- Source:
(readonly) mimeType :string
The mimeType of the file, only accessible after fetching the metadata or downloading/uploading/providing the file
Type:
- string
- Source:
(readonly) name :string
The name of the file
Type:
- string
- Source:
(readonly) parent :string
The parent folder of the file.
Type:
- string
- Source:
(readonly) path :string
The full path of the file.
Type:
- string
- Source:
(readonly) size :number
The size of the file, only accessible after fetching the metadata or downloading/uploading/providing the file
Type:
- number
- Source:
(readonly) url :string
The fully url to the file, can be directly used to link the file, i.e. in link tags ot image sources
Type:
- string
- Source:
Methods
(static) parseETag(eTagopt) → (nullable) {string}
Parses an E-Tag header
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
eTag |
string |
<optional> |
The E-Tag to parse or something falsy |
- Source:
Returns:
Returns the parsed E-Tag or null, if it could not be parsed
- Type
- string
checkAvailable() → {void}
Checks whenever metadata are already loaded of the file, throws an error otherwise
- Source:
Returns:
- Type
- void
conditional(msg, options) → {void}
Makes the given message a conditional request based on the file metadata
Parameters:
Name | Type | Description | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
msg |
connector.Message | The message to make conditional |
|||||||||||
options |
object | additional request options |
|||||||||||
Properties
|
- Source:
Returns:
- Type
- void
delete(deleteOptionsopt, doneCallbackopt, failCallbackopt) → {Promise.<(binding.File|Array.<binding.File>)>}
Deletes a file
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
deleteOptions |
object |
<optional> |
The delete options |
||||||||||
Properties
|
|||||||||||||
doneCallback |
binding.File~deleteCallback |
<optional> |
The callback is invoked after the deletion succeed successfully |
||||||||||
failCallback |
binding.File~failCallback |
<optional> |
The callback is invoked if any error is occurred |
- Source:
Returns:
A promise which will be fulfilled with this file object,
or with a list of all deleted files, if this file is an folder
- Type
- Promise.<(binding.File|Array.<binding.File>)>
download(downloadOptionsopt, doneCallbackopt, failCallbackopt) → {Promise.<(string|Blob|File|ArrayBuffer|json)>}
Download a file and providing it in the requested type
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
downloadOptions |
object |
<optional> |
The download options |
|||||||||||||||
Properties
|
||||||||||||||||||
doneCallback |
binding.File~downloadCallback |
<optional> |
The callback is invoked after the download succeed |
|||||||||||||||
failCallback |
binding.File~failCallback |
<optional> |
The callback is invoked if any error is occurred |
- Source:
Returns:
A promise which will be fulfilled with the downloaded
file content
- Type
- Promise.<(string|Blob|File|ArrayBuffer|json)>
fromJSON(json) → {void}
Deserialize the given JSON file metadata back to this file instance
If the JSON object contains an ID, it must match with this file ID, otherwise an exception is thrown.
Parameters:
Name | Type | Description |
---|---|---|
json |
json | The json to deserialize |
- Source:
Returns:
- Type
- void
loadMetadata(optionsopt, doneCallbackopt, failCallbackopt) → {Promise.<binding.File>}
Gets the file metadata of a file
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
The load metadata options |
||||||||||
Properties
|
|||||||||||||
doneCallback |
binding.File~fileCallback |
<optional> |
The callback is invoked after the metadata is fetched |
||||||||||
failCallback |
binding.File~failCallback |
<optional> |
The callback is invoked if any error has occurred |
- Source:
Returns:
A promise which will be fulfilled with this file
- Type
- Promise.<binding.File>
saveMetadata(optionsopt, doneCallbackopt, failCallbackopt) → {Promise.<binding.File>}
Updates the matadata of this file.
Parameters:
Name | Type | Attributes | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
The save metadata options |
||||||||||
Properties
|
|||||||||||||
doneCallback |
binding.File~fileCallback |
<optional> |
The callback is invoked after the metadata is saved |
||||||||||
failCallback |
binding.File~failCallback |
<optional> |
The callback is invoked if any error has occurred |
- Source:
Returns:
A promise which will be fulfilled with this file
- Type
- Promise.<binding.File>
toJSON() → {json}
Serialize the file metadata of this object to json
- Source:
Returns:
The serialized file metadata as json
- Type
- json
upload(uploadOptionsopt, doneCallbackopt, failCallbackopt) → {Promise.<binding.File>}
Uploads the file content which was provided in the constructor or by uploadOptions.data
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
uploadOptions |
object |
<optional> |
The upload options |
||||||||||||||||||||||||||||||||||||||||||||||||||
Properties
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||
doneCallback |
binding.File~fileCallback |
<optional> |
The callback is invoked after the upload succeed successfully |
||||||||||||||||||||||||||||||||||||||||||||||||||
failCallback |
binding.File~failCallback |
<optional> |
The callback is invoked if any error is occurred |
- Source:
Returns:
A promise which will be fulfilled with this file object
where the metadata is updated
- Type
- Promise.<binding.File>
Type Definitions
deleteCallback(data) → {*}
The delete callback is called, when the asynchronous deletion completes successfully
Parameters:
Name | Type | Description |
---|---|---|
data |
binding.File | The file metadata |
- Source:
Returns:
A Promise, result or undefined
- Type
- *
downloadCallback(data) → {*}
The download callback is called, when the asynchronous download completes successfully
Parameters:
Name | Type | Description |
---|---|---|
data |
string | Blob | File | ArrayBuffer | json | The download file content in the requested format |
- Source:
Returns:
A Promise, result or undefined
- Type
- *
failCallback(error) → {*}
The fail callback is called, when the asynchronous operation is rejected by an error
Parameters:
Name | Type | Description |
---|---|---|
error |
error.PersistentError | The error which reject the operation |
- Source:
Returns:
A Promise, result or undefined
- Type
- *
fileCallback(file) → {*}
The file callback is called, when the asynchronous operation completes successfully
Parameters:
Name | Type | Description |
---|---|---|
file |
binding.File | The updated file metadata |
- Source:
Returns:
A Promise, result or undefined
- Type
- *