com.parse
Class ParseFile

Object
  extended by com.parse.ParseFile

public class ParseFile
extends Object

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

The workflow is to construct a ParseFile with data and optionally a filename. Then save it and set it as a field on a ParseObject.

Example: ParseFile file = new ParseFile("hello".getBytes()); file.save(); ParseObject object = new ParseObject("TestObject"); object.put("file", file); object.save();


Constructor Summary
ParseFile(byte[] data)
          Creates a new file from a byte array.
ParseFile(byte[] data, String contentType)
          Creates a new file from a byte array, and content type.
ParseFile(String name, byte[] data)
          Creates a new file from a byte array and a name.
ParseFile(String name, byte[] data, String contentType)
          Creates a new file from a byte array, file name, and content type.
 
Method Summary
 void cancel()
          Cancels the current network request and callbacks whether it's uploading or fetching data from the server.
 byte[] getData()
          Synchronously gets the data for this object.
 bolts.Task<byte[]> getDataInBackground()
          Gets the data for this object in a background thread.
 void getDataInBackground(GetDataCallback dataCallback)
          Gets the data for this object in a background thread.
 void getDataInBackground(GetDataCallback dataCallback, ProgressCallback progressCallback)
          Gets the data for this object in a background thread.
 bolts.Task<byte[]> getDataInBackground(ProgressCallback progressCallback)
          Gets the data for this object in a background thread.
 String getName()
          The filename.
 String getUrl()
          This returns the url of the file.
 boolean isDataAvailable()
          Whether the file has available data.
 boolean isDirty()
          Whether the file still needs to be saved.
 void save()
          Saves the file to the Parse cloud synchronously.
 bolts.Task<Void> saveInBackground()
          Saves the file to the Parse cloud in a background thread.
 bolts.Task<Void> saveInBackground(ProgressCallback progressCallback)
          Saves the file to the Parse cloud in a background thread.
 void saveInBackground(SaveCallback callback)
          Saves the file to the Parse cloud in a background thread.
 void saveInBackground(SaveCallback saveCallback, ProgressCallback progressCallback)
          Saves the file to the Parse cloud in a background thread.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParseFile

public ParseFile(String name,
                 byte[] data,
                 String contentType)
Creates a new file from a byte array, file name, and content type. Content type will be used instead of auto-detection by file extension.

Parameters:
name - The file's name, ideally with extension. The file name must begin with an alphanumeric character, and consist of alphanumeric characters, periods, spaces, underscores, or dashes.
data - The file's data.
contentType - The file's content type.

ParseFile

public ParseFile(byte[] data)
Creates a new file from a byte array.

Parameters:
data - The file's data.

ParseFile

public ParseFile(String name,
                 byte[] data)
Creates a new file from a byte array and a name. Giving a name with a proper file extension (e.g. ".png") is ideal because it allows Parse to deduce the content type of the file and set appropriate HTTP headers when it is fetched.

Parameters:
name - The file's name, ideally with extension. The file name must begin with an alphanumeric character, and consist of alphanumeric characters, periods, spaces, underscores, or dashes.
data - The file's data.

ParseFile

public ParseFile(byte[] data,
                 String contentType)
Creates a new file from a byte array, and content type. Content type will be used instead of auto-detection by file extension.

Parameters:
data - The file's data.
contentType - The file's content type.
Method Detail

getName

public String getName()
The filename. Before save is called, this is just the filename given by the user (if any). After save is called, that name gets prefixed with a unique identifier.

Returns:
The file's name.

isDirty

public boolean isDirty()
Whether the file still needs to be saved.

Returns:
Whether the file needs to be saved.

isDataAvailable

public boolean isDataAvailable()
Whether the file has available data.


getUrl

public String getUrl()
This returns the url of the file. It's only available after you save or after you get the file from a ParseObject.

Returns:
The url of the file.

save

public void save()
          throws ParseException
Saves the file to the Parse cloud synchronously.

Throws:
ParseException

saveInBackground

public bolts.Task<Void> saveInBackground(ProgressCallback progressCallback)
Saves the file to the Parse cloud in a background thread. `progressCallback` is guaranteed to be called with 100 before saveCallback is called.

Parameters:
progressCallback - A ProgressCallback that is called periodically with progress updates.
Returns:
A Task that will be resolved when the save completes.

saveInBackground

public bolts.Task<Void> saveInBackground()
Saves the file to the Parse cloud in a background thread.

Returns:
A Task that will be resolved when the save completes.

saveInBackground

public void saveInBackground(SaveCallback saveCallback,
                             ProgressCallback progressCallback)
Saves the file to the Parse cloud in a background thread. `progressCallback` is guaranteed to be called with 100 before saveCallback is called.

Parameters:
saveCallback - A SaveCallback that gets called when the save completes.
progressCallback - A ProgressCallback that is called periodically with progress updates.

saveInBackground

public void saveInBackground(SaveCallback callback)
Saves the file to the Parse cloud in a background thread.

Parameters:
callback - A SaveCallback that gets called when the save completes.

getData

public byte[] getData()
               throws ParseException
Synchronously gets the data for this object. You probably want to use ParseFile.getDataInBackground(com.parse.ProgressCallback) instead unless you're already in a background thread.

Throws:
ParseException

getDataInBackground

public bolts.Task<byte[]> getDataInBackground(ProgressCallback progressCallback)
Gets the data for this object in a background thread. `progressCallback` is guaranteed to be called with 100 before dataCallback is called.

Parameters:
progressCallback - A ProgressCallback that is called periodically with progress updates.
Returns:
A Task that is resolved when the data has been fetched.

getDataInBackground

public bolts.Task<byte[]> getDataInBackground()
Gets the data for this object in a background thread. `progressCallback` is guaranteed to be called with 100 before dataCallback is called.

Returns:
A Task that is resolved when the data has been fetched.

getDataInBackground

public void getDataInBackground(GetDataCallback dataCallback,
                                ProgressCallback progressCallback)
Gets the data for this object in a background thread. `progressCallback` is guaranteed to be called with 100 before dataCallback is called.

Parameters:
dataCallback - A GetDataCallback that is called when the get completes.
progressCallback - A ProgressCallback that is called periodically with progress updates.

getDataInBackground

public void getDataInBackground(GetDataCallback dataCallback)
Gets the data for this object in a background thread.

Parameters:
dataCallback - A GetDataCallback that is called when the get completes.

cancel

public void cancel()
Cancels the current network request and callbacks whether it's uploading or fetching data from the server.