File

AV. File

new File(name, data, mimeTypeopt)

Source:
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>}

Source:
Since:
  • 4.13.0
Request file censor.
Parameters:
Name Type Description
objectId String
Returns:
Type
Promise.<string>

(static) createWithoutData(objectId) → {AV.File}

Source:
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}

Source:
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>}

Source:
Since:
  • 4.13.0
Request file censor
Returns:
Type
Promise.<string>

destroy(options) → {Promise}

Source:
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}

Source:
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}

Source:
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}

Source:
Returns the ACL for this file.
Returns:
An instance of AV.ACL.
Type
AV.ACL

metaData(attr, value) → {Object}

Source:

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()

Source:
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}

Source:
Returns the file's owner.
Returns:
The file's owner id.
Type
String

save(optionsopt) → {Promise}

Source:
Saves the file to the AV cloud.
Parameters:
Name Type Attributes Description
options AuthOptions <optional>
AuthOptions plus:
Properties
Name Type Attributes Default Description
onprogress UploadProgressCallback <optional>
文件上传进度,在 Node.js 中无效,回调参数说明详见 UploadProgressCallback
keepFileName boolean <optional>
false 保留下载文件的文件名。
key string <optional>
指定文件的 key。设置该选项需要使用 masterKey
Returns:
Promise that is resolved when the save finishes.
Type
Promise

set(Object, attr, value) → {String|Number|Array|Object}

Source:
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)

Source:
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}

Source:
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}

Source:
Returns the file's size.
Returns:
The file's size in bytes.
Type
Number

thumbnailURL(width, heigth, quality, scaleToFit, fmt) → {String}

Source:
如果文件是图片,获取图片的缩略图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}

Source:
Since:
  • 3.0.0
Returns a JSON version of the file with meta data. Inverse to AV.parseJSON
Returns:
Type
Object

toJSON() → {Object}

Source:
Returns a JSON version of the object.
Returns:
Type
Object

url() → {String}

Source:
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