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(String filename, KinveyClientCallback<Void> callback)
Deletes the given file from the Kinvey file service.
void download(String filename, OutputStream out, DownloaderProgressListener listener)
Download a given file from the Kinvey file service.
void getDownloadUrl(String fileName, KinveyClientCallback<UriLocResponse> callback)
Constructs a request to retrieve a temporary url for purposes of downloading a given file already known to Kinvey.
void getUploadUrl(String fileName, KinveyClientCallback<UriLocResponse> callback)
Constructs a request to retrieve a temporary url for purposes of uploading a given file.
void upload(File file, UploaderProgressListener listener)
Uploads a given file and its contents to the Kinvey file service.
void upload(String name, InputStream inputStream, UploaderProgressListener listener)
Uploads the contents of the stream to the Kinvey file service endpoint.
[Expand]
Inherited Methods
From class com.kinvey.java.File
From class java.lang.Object

Public Methods

public void delete (String filename, KinveyClientCallback<Void> callback)

Deletes the given file from the Kinvey file service.

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

public void download (String filename, 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
filename the name used in metadata for downloadable 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 getDownloadUrl (String fileName, KinveyClientCallback<UriLocResponse> callback)

Constructs a request to retrieve a temporary url for purposes of downloading a given file already known to Kinvey.

The url expires within 60 secs. of calling execute on the request returned.

Parameters
fileName name of the file for which kinvey service is aware
callback an implementation of a client callback to get results on the UI thread from the async call.

public void getUploadUrl (String fileName, KinveyClientCallback<UriLocResponse> callback)

Constructs a request to retrieve a temporary url for purposes of uploading a given file.

The url expires within 60 secs. of calling execute on the request returned.

Parameters
fileName the name of the file used in metadata
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 (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.