public class

File

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

Class Overview

Wraps the File public methods in asynchronous functionality using native Android AsyncTask.

This class is constructed via file() factory 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:

 {@code
    mKinveyClient.file().uploadBlocking("myFileName.txt", file,  new UploaderProgressListener() {

Summary

Nested Classes
class File.DeleteFile  
class File.DownloadMetadata This class will upload new file metadata without actually effecting the file Note it is not recommended to change the filename without ensuring a file exists with the new name. 
class File.DownloadMetadataAndFile This class gets a FileMetaData object from Kinvey, and then downloads the associated File  
class File.DownloadMetadataAndFileQuery This class gets a FileMetaData object from Kinvey, and then downloads the associated File  
class File.UploadMetadata This class will upload new file metadata without actually effecting the file Note it is not recommended to change the filename without ensuring a file exists with the new name. 
class File.UploadMetadataAndFile This class uploads a FileMetaData object to Kinvey, returning another FileMetaData containing the upload URL  
Public Methods
void clearCustomRequestProperties()
File.DeleteFile deleteBlocking(FileMetaData metaData)
Deletes the given file from the Kinvey file service.
File.DeleteFile deleteBlocking(String fileID)
Deletes the given file from the Kinvey file service.
File.DeleteFile deleteBlockingById(String id)
Deletes the given file from the Kinvey file service.
File.DownloadMetadataAndFile downloadBlocking(FileMetaData metaData)
Download a given file from the Kinvey file service.
File.DownloadMetadataAndFileQuery downloadBlocking(Query q)
Query for files to download
File.DownloadMetadataAndFileQuery downloadBlocking(String filename)
This method performs a query to find a file by it's filename.
File.DownloadMetadataAndFileQuery downloadBlocking(String id, Query q)
Attach query parameters when requesting metadata for a specific file.
File.DownloadMetadata downloadMetaDataBlocking(String id)
Downloads metadata for a file, without returning the file iteself.
File.DownloadMetadataAndFileQuery downloadWithTTLBlocking(String id, int ttl)
Download a file with a custom Time-To-Live

Sample usage:

 OutputStream out = new ByteArrayOutputStream(...);
    mKinveyClient.file().downloadBlocking("myFileName.txt", 3600).executeAndDownloadTo(out);
 
void setCache(FilePolicy policy, FileCache cache)
void setClientAppVersion(String appVersion)
void setClientAppVersion(int major, int minor, int revision)
void setCustomRequestProperties(GenericJson customheaders)
void setCustomRequestProperty(String key, Object value)
void setDownloaderProgressListener(DownloaderProgressListener downloaderProgressListener)
void setUploadProgressListener(UploaderProgressListener uploadProgressListener)
File.UploadMetadataAndFile uploadBlocking(String fileName, AbstractInputStreamContent content)
Uploads a given file and its contents to the Kinvey file service.
File.UploadMetadataAndFile uploadBlocking(FileMetaData fileMetaData, AbstractInputStreamContent content)
Uploads a given file and its contents to the Kinvey file service.
File.UploadMetadata uploadMetaDataBlocking(FileMetaData metaData)
Uploads metadata for a file, without modifying the file iteself.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public void clearCustomRequestProperties ()

public File.DeleteFile deleteBlocking (FileMetaData metaData)

Deletes the given file from the Kinvey file service.

Parameters
metaData the metadata of the File to delete (requires an ID)
Returns
  • a valid DELETE request to be executed
Throws
IOException

public File.DeleteFile deleteBlocking (String fileID)

Deletes the given file from the Kinvey file service.

Parameters
fileID the _id of the file to delete
Returns
  • a valid DELETE request to be executed
Throws
IOException

public File.DeleteFile deleteBlockingById (String id)

Deletes the given file from the Kinvey file service.

Parameters
id the metadata of the File to delete (requires an ID)
Returns
  • a valid DELETE request to be executed
Throws
IOException

public File.DownloadMetadataAndFile downloadBlocking (FileMetaData metaData)

Download a given file from the Kinvey file service.

Parameters
metaData the metadata of the file
Returns
  • a valid request to be executed for the download operation from Kinvey file service
Throws
IOException

public File.DownloadMetadataAndFileQuery downloadBlocking (Query q)

Query for files to download

Parameters
q the query to execute for file metadata
Returns
  • a valid request to be executed
Throws
IOException

public File.DownloadMetadataAndFileQuery downloadBlocking (String filename)

This method performs a query to find a file by it's filename. As Kinvey File now supports non-unique file names, this method will only return a single file with this name.@return

Throws
IOException

public File.DownloadMetadataAndFileQuery downloadBlocking (String id, Query q)

Attach query parameters when requesting metadata for a specific file. Use this method to specify a custom time to live.

Sample usage:

 Query q = new Query();
    q.equals("ttl_in_seconds", 3600);  //set a new ttl for the download URL
    OutputStream out = new ByteArrayOutputStream(...);
    mKinveyClient.file().downloadBlocking("myFileName.txt", q).executeAndDownloadTo(out);
 

Parameters
id - the unique id of the file
q - the query to execute
Returns
  • a valid download request ready to be executed
Throws
IOException

public File.DownloadMetadata downloadMetaDataBlocking (String id)

Downloads metadata for a file, without returning the file iteself.

Parameters
id the id of the metadata
Returns
  • a valid PUT or POST request to be executed
Throws
IOException

public File.DownloadMetadataAndFileQuery downloadWithTTLBlocking (String id, int ttl)

Download a file with a custom Time-To-Live

Sample usage:

 OutputStream out = new ByteArrayOutputStream(...);
    mKinveyClient.file().downloadBlocking("myFileName.txt", 3600).executeAndDownloadTo(out);
 

Parameters
id - the unique _id of the file to download
ttl - a custom TTL, in milliseconds
Returns
Throws
IOException

public void setCache (FilePolicy policy, FileCache cache)

public void setClientAppVersion (String appVersion)

public void setClientAppVersion (int major, int minor, int revision)

public void setCustomRequestProperties (GenericJson customheaders)

public void setCustomRequestProperty (String key, Object value)

public void setDownloaderProgressListener (DownloaderProgressListener downloaderProgressListener)

Parameters
downloaderProgressListener the listener to receive notifications as the download progresses

public void setUploadProgressListener (UploaderProgressListener uploadProgressListener)

Parameters
uploadProgressListener the listener to receive notifications as the upload progresses

public File.UploadMetadataAndFile uploadBlocking (String fileName, AbstractInputStreamContent content)

Uploads a given file and its contents to the Kinvey file service.

Parameters
fileName the filename used for the metadata
content the input stream from which the file contents will be sourced
Returns
  • a valid request to be executed for the upload operation to Kinvey
Throws
IOException if initializing the request fails

public File.UploadMetadataAndFile uploadBlocking (FileMetaData fileMetaData, AbstractInputStreamContent content)

Uploads a given file and its contents to the Kinvey file service.

Parameters
fileMetaData Metadata object about the file to uplaod
content the input stream from which the file contents will be sourced
Returns
  • a valid request to be executed for the upload operation to Kinvey
Throws
IOException if initializing the request fails

public File.UploadMetadata uploadMetaDataBlocking (FileMetaData metaData)

Uploads metadata for a file, without modifying the file iteself.

Parameters
metaData the metadata of the File to upload
Returns
  • a valid PUT or POST request to be executed
Throws
IOException