lib/file.js
function(file, type) {
    var promise = new Parse.Promise();

    if (typeof(FileReader) === "undefined") {
      return Parse.Promise.error(new Parse.Error(
          Parse.Error.FILE_READ_ERROR,
          "Attempted to use a FileReader on an unsupported browser."));
    }

    var reader = new FileReader();
    reader.onloadend = function() {
      if (reader.readyState !== 2) {
        promise.reject(new Parse.Error(
            Parse.Error.FILE_READ_ERROR,
            "Error reading file."));
        return;
      }

      var dataURL = reader.result;
      var matches = /^data:([^;]*);base64,(.*)$/.exec(dataURL);
      if (!matches) {
        promise.reject(new Parse.Error(
            Parse.ERROR.FILE_READ_ERROR,
            "Unable to interpret data URL: " + dataURL));
        return;
      }

      promise.resolve(matches[2], type || matches[1]);
    };
    reader.readAsDataURL(file);
    return promise;
  }
function(file, type) {
    var promise = new Parse.Promise();

    if (typeof(FileReader) === "undefined") {
      return Parse.Promise.error(new Parse.Error(
          Parse.Error.FILE_READ_ERROR,
          "Attempted to use a FileReader on an unsupported browser."));
    }

    var reader = new FileReader();
    reader.onloadend = function() {
      if (reader.readyState !== 2) {
        promise.reject(new Parse.Error(
            Parse.Error.FILE_READ_ERROR,
            "Error reading file."));
        return;
      }

      var dataURL = reader.result;
      var matches = /^data:([^;]*);base64,(.*)$/.exec(dataURL);
      if (!matches) {
        promise.reject(new Parse.Error(
            Parse.ERROR.FILE_READ_ERROR,
            "Unable to interpret data URL: " + dataURL));
        return;
      }

      promise.resolve(matches[2], type || matches[1]);
    };
    reader.readAsDataURL(file);
    return promise;
  }
function ( file , type ) { var promise = new Parse . Promise ( ) ; if ( typeof ( FileReader ) === "undefined" ) { return Parse . Promise . error ( new Parse . Error ( Parse . Error . FILE_READ_ERROR , "Attempted to use a FileReader on an unsupported browser." ) ) ; } var reader = new FileReader ( ) ; reader . onloadend = function ( ) { if ( reader . readyState !== 2 ) { promise . reject ( new Parse . Error ( Parse . Error . FILE_READ_ERROR , "Error reading file." ) ) ; return ; } var dataURL = reader . result ; var matches = / ^data:([^;]*);base64,(.*)$ / . exec ( dataURL ) ; if ( ! matches ) { promise . reject ( new Parse . Error ( Parse . ERROR . FILE_READ_ERROR , "Unable to interpret data URL: " + dataURL ) ) ; return ; } promise . resolve ( matches [ 2 ] , type || matches [ 1 ] ) ; } ; reader . readAsDataURL ( file ) ; return promise ; }
Reads a File using a FileReader.
@param file {File} the File to read.
@param type {String} (optional) the mimetype to override with.
@return {Parse.Promise} A Promise that will be fulfilled with a
base64-encoded string of the data and its mime type.
Reads a File using a FileReader .