Package com.parse
Class ParseFile
- java.lang.Object
-
- com.parse.ParseFile
-
public class ParseFile extends java.lang.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 aParseObject
.Example:
ParseFile file = new ParseFile("hello".getBytes()); file.save(); ParseObject object = new ParseObject("TestObject"); object.put("file", file); object.save();
-
-
Field Summary
Fields Modifier and Type Field Description static <any>
CREATOR
-
Constructor Summary
Constructors Constructor Description ParseFile(byte[] data)
Creates a new file from a byte array.ParseFile(byte[] data, java.lang.String contentType)
Creates a new file from a byte array, and content type.ParseFile(java.io.File file)
Creates a new file from a file pointer.ParseFile(java.io.File file, java.lang.String contentType)
Creates a new file from a file pointer, and content type.ParseFile(java.lang.String name, byte[] data)
Creates a new file from a byte array and a name.ParseFile(java.lang.String name, byte[] data, java.lang.String contentType)
Creates a new file from a byte array, file name, and content type.ParseFile(java.lang.String name, Uri uri, java.lang.String contentType)
Creates a new file from a content uri, file name, and content type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cancel()
Cancels the operations for thisParseFile
if they are still in the task queue.int
describeContents()
byte[]
getData()
Synchronously gets the data from cache if available or fetches its content from the network.<any>
getDataInBackground()
Asynchronously gets the data from cache if available or fetches its content from the network.void
getDataInBackground(GetDataCallback dataCallback)
Asynchronously gets the data from cache if available or fetches its content from the network.void
getDataInBackground(GetDataCallback dataCallback, ProgressCallback progressCallback)
Asynchronously gets the data from cache if available or fetches its content from the network.<any>
getDataInBackground(ProgressCallback progressCallback)
Asynchronously gets the data from cache if available or fetches its content from the network.java.io.InputStream
getDataStream()
Synchronously gets the data stream from cached file if available or fetches its content from the network, saves the content as cached file and returns the data stream of the cached file.<any>
getDataStreamInBackground()
Asynchronously gets the data stream from cached file if available or fetches its content from the network, saves the content as cached file and returns the data stream of the cached file.void
getDataStreamInBackground(GetDataStreamCallback dataStreamCallback)
Asynchronously gets the data stream from cached file if available or fetches its content from the network, saves the content as cached file and returns the data stream of the cached file.void
getDataStreamInBackground(GetDataStreamCallback dataStreamCallback, ProgressCallback progressCallback)
Asynchronously gets the data stream from cached file if available or fetches its content from the network, saves the content as cached file and returns the data stream of the cached file.<any>
getDataStreamInBackground(ProgressCallback progressCallback)
Asynchronously gets the data stream from cached file if available or fetches its content from the network, saves the content as cached file and returns the data stream of the cached file.java.io.File
getFile()
Synchronously gets the file pointer from cache if available or fetches its content from the network.<any>
getFileInBackground()
Asynchronously gets the file pointer from cache if available or fetches its content from the network.void
getFileInBackground(GetFileCallback fileCallback)
Asynchronously gets the file pointer from cache if available or fetches its content from the network.void
getFileInBackground(GetFileCallback fileCallback, ProgressCallback progressCallback)
Asynchronously gets the file pointer from cache if available or fetches its content from the network.<any>
getFileInBackground(ProgressCallback progressCallback)
Asynchronously gets the file pointer from cache if available or fetches its content from the network.java.lang.String
getName()
The filename.java.lang.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.<any>
saveInBackground()
Saves the file to the Parse cloud in a background thread.<any>
saveInBackground(ProgressCallback uploadProgressCallback)
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.void
writeToParcel(Parcel dest, int flags)
-
-
-
Constructor Detail
-
ParseFile
public ParseFile(java.io.File file)
Creates a new file from a file pointer.- Parameters:
file
- The file.
-
ParseFile
public ParseFile(java.io.File file, java.lang.String contentType)
Creates a new file from a file pointer, and content type. Content type will be used instead of auto-detection by file extension.- Parameters:
file
- The file.contentType
- The file's content type.
-
ParseFile
public ParseFile(java.lang.String name, byte[] data, java.lang.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(java.lang.String name, Uri uri, java.lang.String contentType)
Creates a new file from a content uri, 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.uri
- The file uri.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(java.lang.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, java.lang.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 java.lang.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 java.lang.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 <any> saveInBackground(ProgressCallback uploadProgressCallback)
Saves the file to the Parse cloud in a background thread. `progressCallback` is guaranteed to be called with 100 before saveCallback is called.- Parameters:
uploadProgressCallback
- A ProgressCallback that is called periodically with progress updates.- Returns:
- A Task that will be resolved when the save completes.
-
saveInBackground
public <any> 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 from cache if available or fetches its content from the network. You probably want to usegetDataInBackground()
instead unless you're already in a background thread.- Throws:
ParseException
-
getDataInBackground
public <any> getDataInBackground(ProgressCallback progressCallback)
Asynchronously gets the data from cache if available or fetches its content from the network. AProgressCallback
will be called periodically with progress updates.- Parameters:
progressCallback
- AProgressCallback
that is called periodically with progress updates.- Returns:
- A Task that is resolved when the data has been fetched.
-
getDataInBackground
public <any> getDataInBackground()
Asynchronously gets the data from cache if available or fetches its content from the network.- Returns:
- A Task that is resolved when the data has been fetched.
-
getDataInBackground
public void getDataInBackground(GetDataCallback dataCallback, ProgressCallback progressCallback)
Asynchronously gets the data from cache if available or fetches its content from the network. AProgressCallback
will be called periodically with progress updates. AGetDataCallback
will be called when the get completes.- Parameters:
dataCallback
- AGetDataCallback
that is called when the get completes.progressCallback
- AProgressCallback
that is called periodically with progress updates.
-
getDataInBackground
public void getDataInBackground(GetDataCallback dataCallback)
Asynchronously gets the data from cache if available or fetches its content from the network. AGetDataCallback
will be called when the get completes.- Parameters:
dataCallback
- AGetDataCallback
that is called when the get completes.
-
getFile
public java.io.File getFile() throws ParseException
Synchronously gets the file pointer from cache if available or fetches its content from the network. You probably want to usegetFileInBackground()
instead unless you're already in a background thread. Note: TheFile
location may change without notice and should not be stored to be accessed later.- Throws:
ParseException
-
getFileInBackground
public <any> getFileInBackground(ProgressCallback progressCallback)
Asynchronously gets the file pointer from cache if available or fetches its content from the network. TheProgressCallback
will be called periodically with progress updates. Note: TheFile
location may change without notice and should not be stored to be accessed later.- Parameters:
progressCallback
- AProgressCallback
that is called periodically with progress updates.- Returns:
- A Task that is resolved when the file pointer of this object has been fetched.
-
getFileInBackground
public <any> getFileInBackground()
Asynchronously gets the file pointer from cache if available or fetches its content from the network. Note: TheFile
location may change without notice and should not be stored to be accessed later.- Returns:
- A Task that is resolved when the data has been fetched.
-
getFileInBackground
public void getFileInBackground(GetFileCallback fileCallback, ProgressCallback progressCallback)
Asynchronously gets the file pointer from cache if available or fetches its content from the network. TheGetFileCallback
will be called when the get completes. TheProgressCallback
will be called periodically with progress updates. TheProgressCallback
is guaranteed to be called with 100 before theGetFileCallback
is called. Note: TheFile
location may change without notice and should not be stored to be accessed later.- Parameters:
fileCallback
- AGetFileCallback
that is called when the get completes.progressCallback
- AProgressCallback
that is called periodically with progress updates.
-
getFileInBackground
public void getFileInBackground(GetFileCallback fileCallback)
Asynchronously gets the file pointer from cache if available or fetches its content from the network. TheGetFileCallback
will be called when the get completes. Note: TheFile
location may change without notice and should not be stored to be accessed later.- Parameters:
fileCallback
- AGetFileCallback
that is called when the get completes.
-
getDataStream
public java.io.InputStream getDataStream() throws ParseException
Synchronously gets the data stream from cached file if available or fetches its content from the network, saves the content as cached file and returns the data stream of the cached file. You probably want to usegetDataStreamInBackground(com.parse.ProgressCallback)
instead unless you're already in a background thread.- Throws:
ParseException
-
getDataStreamInBackground
public <any> getDataStreamInBackground(ProgressCallback progressCallback)
Asynchronously gets the data stream from cached file if available or fetches its content from the network, saves the content as cached file and returns the data stream of the cached file. TheProgressCallback
will be called periodically with progress updates.- Parameters:
progressCallback
- AProgressCallback
that is called periodically with progress updates.- Returns:
- A Task that is resolved when the data stream of this object has been fetched.
-
getDataStreamInBackground
public <any> getDataStreamInBackground()
Asynchronously gets the data stream from cached file if available or fetches its content from the network, saves the content as cached file and returns the data stream of the cached file.- Returns:
- A Task that is resolved when the data stream has been fetched.
-
getDataStreamInBackground
public void getDataStreamInBackground(GetDataStreamCallback dataStreamCallback, ProgressCallback progressCallback)
Asynchronously gets the data stream from cached file if available or fetches its content from the network, saves the content as cached file and returns the data stream of the cached file. TheGetDataStreamCallback
will be called when the get completes. TheProgressCallback
will be called periodically with progress updates. TheProgressCallback
is guaranteed to be called with 100 beforeGetDataStreamCallback
is called.- Parameters:
dataStreamCallback
- AGetDataStreamCallback
that is called when the get completes.progressCallback
- AProgressCallback
that is called periodically with progress updates.
-
getDataStreamInBackground
public void getDataStreamInBackground(GetDataStreamCallback dataStreamCallback)
Asynchronously gets the data stream from cached file if available or fetches its content from the network, saves the content as cached file and returns the data stream of the cached file. TheGetDataStreamCallback
will be called when the get completes.- Parameters:
dataStreamCallback
- AGetDataStreamCallback
that is called when the get completes.
-
cancel
public void cancel()
Cancels the operations for thisParseFile
if they are still in the task queue. However, if a network request has already been started for an operation, the network request will not be canceled.
-
describeContents
public int describeContents()
-
writeToParcel
public void writeToParcel(Parcel dest, int flags)
-
-