java.lang.Object | ||
↳ | com.kinvey.java.File | |
↳ | com.kinvey.android.AsyncFile |
Wraps the com.kinvey.java.File public methods in asynchronous functionality using native Android AsyncTask.
This functionality can be accessed through the file()
convenience method.
The callback mechanism for this api is extended to include the progressChanged(com.kinvey.java.core.MediaHttpUploader)
method, which receives notifications as the upload process transitions through and progresses with the upload.
process.
Sample usage:
mKinveyClient.file().upload(file, new UploaderProgressListener() {
public void onSuccess(Void result) {
Log.i(TAG, "successfully upload file");
public void onFailure(Throwable error) {
Log.e(TAG, "failed to upload file.", error);
}
public void progressChanged(MediaHttpUploader uploader) throws IOException {
Log.i(TAG, "upload progress: " + uploader.getUploadState());
switch (uploader.getUploadState()) {
case INITIATION_STARTED:
Log.i(TAG, "Initiation Started");
break;
case INITIATION_COMPLETE:
Log.i(TAG, "Initiation Completed");
break;
case DOWNLOAD_IN_PROGRESS:
Log.i(TAG, "Upload in progress");
Log.i(TAG, "Upload percentage: " + uploader.getProgress());
break;
case DOWNLOAD_COMPLETE:
Log.i(TAG, "Upload Completed!");
break;
}
}
});
}
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
void | clearFileStorage(Context applicationContext) | ||||||||||
void |
delete(FileMetaData metadata, KinveyClientCallback<KinveyDeleteResponse> callback)
Deletes the given file from the Kinvey file service.
| ||||||||||
void |
download(Query q, OutputStream out, DownloaderProgressListener listener)
Download a file by Query, only the first result will be downloaded.
| ||||||||||
void |
download(FileMetaData metaData, OutputStream out, DownloaderProgressListener listener)
Download a given file from the Kinvey file service.
| ||||||||||
void |
downloadMetaData(String id, KinveyClientCallback<FileMetaData> callback)
Downloads just the metadata of a file
| ||||||||||
void |
downloadWithTTL(String id, int ttl, OutputStream out, DownloaderProgressListener listener)
Download a file asyncronously with a custom time to live.
| ||||||||||
void |
upload(File file, UploaderProgressListener listener)
Uploads a given file and its contents to the Kinvey file service.
| ||||||||||
void |
upload(FileMetaData meta, File file, UploaderProgressListener listener)
Upload a java.io.File with it's associated metadata
| ||||||||||
void |
upload(FileMetaData meta, InputStream inputStream, UploaderProgressListener listener)
Uploads the contents of the stream to the Kinvey file service endpoint.
| ||||||||||
void |
upload(String name, InputStream inputStream, UploaderProgressListener listener)
Uploads the contents of the stream to the Kinvey file service endpoint.
| ||||||||||
void |
uploadMetaData(FileMetaData meta, KinveyClientCallback<FileMetaData> callback)
Upload metadata for an existing file
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
Deletes the given file from the Kinvey file service.
metadata | the metadata of the file |
---|---|
callback | an implementation of a client callback to get results on the UI thread from the async call. |
Download a file by Query, only the first result will be downloaded.
q | - the query, with a limit of 1 |
---|---|
out | - where to download the file |
listener | - for progress notifications |
Download a given file from the Kinvey file service.
The UI thread can receive updates on the status by passing in a progress listener.
public static class MyDownloadProgressListener implements DownloaderProgressListener {
public void progressChanged(MediaHttpDownloader downloader) throws IOException {
switch (downloader.getDownloadState()) {
case DOWNLOAD_IN_PROGRESS:
Log.i(TAG, "Download in progress");
Log.i(TAG, "Download percentage: " + downloader.getProgress());
break;
case DOWNLOAD_COMPLETE:
Log.i(TAG, "Download Completed!");
break;
}
public void onSuccess(Void result) {}
public void onFailure(Throwable error) {
Log.e(TAG, "Upload failed", error);
}
}
}
metaData | the metadata of the file. |
---|---|
out | a java.io.OutputStream object. |
listener | an implementation of a client listener to get results on the UI thread from the async call. |
Downloads just the metadata of a file
id | the metadata of the file |
---|---|
callback | an implementation of a client callback to get results on the UI thread from the async call. |
Download a file asyncronously with a custom time to live.
id | - the id of the file to download |
---|---|
ttl | - the custom ttl to use for the download URL |
out | - where to download the file |
listener | - for progress notifications |
Uploads a given file and its contents to the Kinvey file service.
The UI thread can receive updates on the status by passing in a progress listener.
Sample usage:
public static class MyUploadProgressListener implements UploaderProgressListener {
public void progressChanged(MediaHttpUploader uploader) throws IOException {
switch (uploader.getUploadState()) {
case INITIATION_STARTED:
Log.i(TAG, "Initiation Started");
break;
case INITIATION_COMPLETE:
Log.i(TAG, "Initiation Completed");
break;
case DOWNLOAD_IN_PROGRESS:
Log.i(TAG, "Upload in progress");
Log.i(TAG, "Upload percentage: " + uploader.getProgress());
break;
case DOWNLOAD_COMPLETE:
Log.i(TAG, "Upload Completed!");
break;
}
public void onSuccess(Void result) {}
public void onFailure(Throwable error) {
Log.e(TAG, "Upload failed", error);
}
}
}
file | the file to be uploaded |
---|---|
listener | an implementation of a client listener that gets notifications on the UI thread from the underlying thread. |
Upload a java.io.File with it's associated metadata
meta | the metadata of the file to upload |
---|---|
file | the file itself |
listener | listener for callbacks about upload progress |
Uploads the contents of the stream to the Kinvey file service endpoint.
meta | the metadata of the file to upload |
---|---|
inputStream | stream to be uploaded |
listener | an implementation of a client listener to get results on the UI thread from the async call. |
Uploads the contents of the stream to the Kinvey file service endpoint.
name | name to refer to the blob when stored with the file service endpoint |
---|---|
inputStream | stream to be uploaded |
listener | an implementation of a client listener to get results on the UI thread from the async call. |
Upload metadata for an existing file
meta | the FileMetaData to update |
---|---|
callback | an implementation of a client callback to get results on the UI thread from the async call. |