new File(name, data, mimeTypeopt)
An AV.File is a local representation of a file that is saved to the AV
cloud.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
String | The file's name. This will change to a unique value once the file has finished saving. | |
data |
Array | The data for the file, as either:
1. an Array of byte value Numbers, or
2. an Object like { base64: "..." } with a base64-encoded String.
3. a Blob(File) selected with a file upload control in a browser.
4. an Object like { blob: {uri: "..."} } that mimics Blob
in some non-browser environments such as React Native.
5. a Buffer in Node.js runtime.
6. a Stream in Node.js runtime.
For example:var fileUploadControl = $("#profilePhotoFileUpload")[0]; if (fileUploadControl.files.length > 0) { var file = fileUploadControl.files[0]; var name = "photo.jpg"; var file = new AV.File(name, file); file.save().then(function() { // The file has been saved to AV. }, function(error) { // The file either could not be read, or could not be saved to AV. }); } |
|
mimeType |
String |
<optional> |
Content-Type header to use for the file. If this is omitted, the content type will be inferred from the name's extension. |
Methods
(static) censor(objectId) → {Promise.<string>}
Request file censor.
Parameters:
Name | Type | Description |
---|---|---|
objectId |
String |
Returns:
- Type
- Promise.<string>
(static) createWithoutData(objectId) → {AV.File}
Creates a file object with exists objectId.
Parameters:
Name | Type | Description |
---|---|---|
objectId |
String | The objectId string |
Returns:
the file object
- Type
- AV.File
(static) withURL(name, url, metaDataopt, typeopt) → {AV.File}
Creates a fresh AV.File object with exists url for saving to AVOS Cloud.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
String | the file name | |
url |
String | the file url. | |
metaData |
Object |
<optional> |
the file metadata object. |
type |
String |
<optional> |
Content-Type header to use for the file. If this is omitted, the content type will be inferred from the name's extension. |
Returns:
the file object
- Type
- AV.File
censor() → {Promise.<string>}
Request file censor
Returns:
- Type
- Promise.<string>
destroy(options) → {Promise}
Destroy the file.
Parameters:
Name | Type | Description |
---|---|---|
options |
AuthOptions |
Returns:
A promise that is fulfilled when the destroy
completes.
- Type
- Promise
fetch(fetchOptions, options) → {Promise}
fetch the file from server. If the server's representation of the
model differs from its current attributes, they will be overriden,
Parameters:
Name | Type | Description |
---|---|---|
fetchOptions |
Object | Optional options to set 'keys', 'include' and 'includeACL' option. |
options |
AuthOptions |
Returns:
A promise that is fulfilled when the fetch
completes.
- Type
- Promise
get(The) → {Any}
Gets the attributs of the file object.
Parameters:
Name | Type | Description |
---|---|---|
The |
String | attribute name which want to get. |
Returns:
- Type
- Any
getACL() → {AV.ACL}
Returns the ACL for this file.
Returns:
An instance of AV.ACL.
- Type
- AV.ACL
metaData(attr, value) → {Object}
Returns the file's metadata JSON object if no arguments is given.Returns the metadata value if a key is given.Set metadata value if key and value are both given.
var metadata = file.metaData(); //Get metadata JSON object. var size = file.metaData('size'); // Get the size metadata value. file.metaData('format', 'jpeg'); //set metadata attribute and value.
Parameters:
Name | Type | Description |
---|---|---|
attr |
String | an optional metadata key. |
value |
Object | an optional metadata value. |
Returns:
The file's metadata JSON object.
- Type
- Object
name()
Gets the name of the file. Before save is called, this is the filename
given by the user. After save is called, that name gets prefixed with a
unique identifier.
ownerId() → {String}
Returns the file's owner.
Returns:
The file's owner id.
- Type
- String
save(optionsopt) → {Promise}
Saves the file to the AV cloud.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
AuthOptions |
<optional> |
AuthOptions plus:
Properties
|
Returns:
Promise that is resolved when the save finishes.
- Type
- Promise
set(Object, attr, value) → {String|Number|Array|Object}
Set the metaData of the file object.
Parameters:
Name | Type | Description |
---|---|---|
Object |
Object | is an key value Object for setting metaData. |
attr |
String | is an optional metadata key. |
value |
Object | is an optional metadata value. |
Returns:
- Type
- String | Number | Array | Object
setACL(acl)
Sets the ACL to be used for this file.
Parameters:
Name | Type | Description |
---|---|---|
acl |
AV.ACL | An instance of AV.ACL. |
setUploadHeader(key, value) → {AV.File}
Set a header for the upload request.
For more infomation, go to https://url.leanapp.cn/avfile-upload-headers
Parameters:
Name | Type | Description |
---|---|---|
key |
String | header key |
value |
String | header value |
Returns:
this
- Type
- AV.File
size() → {Number}
Returns the file's size.
Returns:
The file's size in bytes.
- Type
- Number
thumbnailURL(width, heigth, quality, scaleToFit, fmt) → {String}
如果文件是图片,获取图片的缩略图URL。可以传入宽度、高度、质量、格式等参数。
Parameters:
Name | Type | Description |
---|---|---|
width |
Number | 宽度,单位:像素 |
heigth |
Number | 高度,单位:像素 |
quality |
Number | 质量,1-100的数字,默认100 |
scaleToFit |
Number | 是否将图片自适应大小。默认为true。 |
fmt |
String | 格式,默认为png,也可以为jpeg,gif等格式。 |
Returns:
缩略图URL
- Type
- String
toFullJSON() → {Object}
Returns a JSON version of the file with meta data.
Inverse to AV.parseJSON
Returns:
- Type
- Object
toJSON() → {Object}
Returns a JSON version of the object.
Returns:
- Type
- Object
url() → {String}
Gets the url of the file. It is only available after you save the file or
after you get the file from a AV.Object.
Returns:
- Type
- String