ParseFile

Parse~ ParseFile

A Parse.File is a local representation of a file that is saved to the Parse cloud.

Constructor

new ParseFile(name, data, type)

Parameters:
Name Type Description
name String

The file's name. This will be prefixed by a unique value once the file has finished saving. The file name must begin with an alphanumeric character, and consist of alphanumeric characters, periods, spaces, underscores, or dashes.

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. an Object like { uri: "..." } with a uri String. 4. a File object selected with a file upload control. (3) only works in Firefox 3.6+, Safari 6.0.2+, Chrome 7+, and IE 10+. For example:

var fileUploadControl = $("#profilePhotoFileUpload")[0];
if (fileUploadControl.files.length > 0) {
  var file = fileUploadControl.files[0];
  var name = "photo.jpg";
  var parseFile = new Parse.File(name, file);
  parseFile.save().then(function() {
    // The file has been saved to Parse.
  }, function(error) {
    // The file either could not be read, or could not be saved to Parse.
  });
}
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.

Methods

cancel()

Aborts the request if it has already been sent.

(async) getData() → {Promise}

Return the data for the file, downloading it if not already present. Data is present if initialized with Byte Array, Base64 or Saved with Uri. Data is cleared if saved with File object selected with a file upload control

Returns:
Type:
Promise

Promise that is resolve with base64 data

name() → {String}

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.

Returns:
Type:
String

save(options) → {Promise}

Saves the file to the Parse cloud.

Parameters:
Name Type Description
options Object
  • Valid options are:
    • useMasterKey: In Cloud Code and Node only, causes the Master Key to be used for this request.
    • progress: In Browser only, callback for upload progress
Returns:
Type:
Promise

Promise that is resolved when the save finishes.

url(options) → {String}

Gets the url of the file. It is only available after you save the file or after you get the file from a Parse.Object.

Parameters:
Name Type Description
options Object

An object to specify url options

Returns:
Type:
String