public class

AsyncFile

extends File
java.lang.Object
   ↳ com.kinvey.java.File
     ↳ com.kinvey.android.AsyncFile

Class Overview

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;
            }
        }
    });
 }
 

Summary

Public Methods
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<Void> callback)
Downloads just the metadata of a file
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(String id, KinveyClientCallback<Void> callback)
Upload metadata for an existing file
[Expand]
Inherited Methods
From class com.kinvey.java.File
From class java.lang.Object

Public Methods

public void delete (FileMetaData metadata, KinveyClientCallback<KinveyDeleteResponse> callback)

Deletes the given file from the Kinvey file service.

Parameters
metadata the metadata of the file
callback an implementation of a client callback to get results on the UI thread from the async call.

public void download (Query q, OutputStream out, DownloaderProgressListener listener)

Download a file by Query, only the first result will be downloaded.

Parameters
q - the query, with a limit of 1
out - where to download the file
listener - for progress notifications

public void download (FileMetaData metaData, OutputStream out, DownloaderProgressListener listener)

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);
         }

     }
 }
 

Parameters
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.

public void downloadMetaData (String id, KinveyClientCallback<Void> callback)

Downloads just the metadata of a file

Parameters
id the metadata of the file
callback an implementation of a client callback to get results on the UI thread from the async call.

public void upload (File file, UploaderProgressListener listener)

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);
         }
     }
 }
 

Parameters
file the file to be uploaded
listener an implementation of a client listener that gets notifications on the UI thread from the underlying thread.

public void upload (FileMetaData meta, File file, UploaderProgressListener listener)

Upload a java.io.File with it's associated metadata

Parameters
meta the metadata of the file to upload
file the file itself
listener listener for callbacks about upload progress

public void upload (FileMetaData meta, InputStream inputStream, UploaderProgressListener listener)

Uploads the contents of the stream to the Kinvey file service endpoint.

Parameters
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.

public void upload (String name, InputStream inputStream, UploaderProgressListener listener)

Uploads the contents of the stream to the Kinvey file service endpoint.

Parameters
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.

public void uploadMetaData (String id, KinveyClientCallback<Void> callback)

Upload metadata for an existing file

Parameters
id the metadata of the file
callback an implementation of a client callback to get results on the UI thread from the async call.