App42 Cloud API

Java and Groovy Cloud SDK

File Storage

In order to use the various functions available under a particular API, a developer will have to create an instance of ServiceAPI by passing the apiKey and the secretKey which has been received while creating an app.

	ServiceAPI api = new ServiceAPI("<API_KEY>","<SECRET_KEY>");    

After initialization, developer needs to call the buildXXXService method on ServiceAPI instance to get the instance of the particular API that you wish to build. For example, To build an instance of UploadService, buildUploadService() method needs to be called.

	UploadService uploadService = api.buildUploadService();

Once the API instance has been retrieved, You are ready to use the functions available for that particular API.

The methods available under a particular API will return the domain object (like Upload in this case) as a response which will have the accessor / mutator to access the available properties for that object. You can get the response in the form of JSON as well. We have provided the JSON response with every function detail which can be retrieved by calling the toString() on the returned object.

String name = "TextFile007";
String filePath = "Local file path";
String description = "TextFile_123";						

Upload upload = uploadService.uploadFile(name,filePath,UploadFileType.IMAGE,description); /* returns the Upload object. */  
ArrayList<Upload.File> fileList =  upload.getFileList();  
for(Upload.File file : fileList)
{
	System.out.println("File Name is " + file.getName());
	System.out.println("File Type is " + file.getType());
	System.out.println("File Url is " + file.getUrl());
	System.out.println("File Description is " + file.getDescription());
}
String jsonResponse = upload.toString(); /* returns the response in JSON format. */   

The functions available under File Upload API can throw some exceptions in abnormal conditions. Example of the same has been given below.

E.g. If App developer is requesting for the files by type which is not in database, the function will throw the App42Exception (as shown below) with message as "Not Found" and the appErrorCode as "2102" and the details as "Files for the user '<userName>' do not exist".

String userName = "Nick";

try
{
	Upload upload = uploadService.getAllFilesByUser(userName);
}
catch(App42Exception ex) 
{
	int appErrorCode = ex.getAppErrorCode();
	int httpErrorCode = ex.getHttpErrorCode();
	if(appErrorCode == 2102)
	{
		// Handle here for Not found (Files for the user '<userName>' do not exist.)
	}  
	else if(appErrorCode == 1401)
	{
		// handle here for Client is not authorized
	}
	else if(appErrorCode == 1500)
	{
		// handle here for Internal Server Error
	}
	String jsonText = ex.getMessage(); /* returns the Exception text in JSON format. (as shown below)*/	
}   
	{
		"app42Fault": {
			"httpErrorCode": 404,
			"appErrorCode": 2102,
			"message": "Not Found",
			"details": "Files for the user 'Nick' do not exist"
		}
	}		

Below are the HTTP Error Codes and their description, the function under the File Upload API can throw.

/*
1400 - BAD REQUEST - The Request parameters are invalid
1401 - UNAUTHORIZED - Client is not authorized
1500 - INTERNAL SERVER ERROR - Internal Server Error. Please try again	
*/						

Below are the Application Error Codes and their description, the function under the File Upload API can throw.

/*
2100 - BAD REQUEST - The request parameters are invalid. File by the name '<name>' already exists. 
2101 - NOT FOUND - Files do not exist. 
2102 - NOT FOUND - Files for the user '<userName>' do not exist.
2103 - NOT FOUND - The file with the name '<name>' does not exist. 
2104 - NOT FOUND - There are no files to remove.
2105 - NOT FOUND - The file with type '<type>' does not exist.
2106 - NOT FOUND - The number of files are less than the specified offset : <offset>.
2107 - NOT FOUND - The number of files for the user '<userName>' are less than the specified offset : <offset>.
2108 - NOT FOUND - The number of files with type '<type>' are less than the specified offset : <offset>.
*/				

Various functions available under File Upload API has been explained below.

public Upload uploadFile(String name, String filePath, UploadFileType fileType, String description) throws App42Exception

Uploads file on the cloud.

Parameters:

name - The name for the file which has to be saved. It is used to retrieve the file
filePath - The local path for the file
fileType - The type of the file. File can be either Audio, Video, Image, Binary, Txt, xml, json, csv or other Use the static constants e.g. Upload.AUDIO, Upload.XML etc.
description - Description of the file to be uploaded.

Returns:

Upload object

Response: Upload Object

Exception:

The method throws the following exception with the error code.
/*
2100 - BAD REQUEST - The request parameters are invalid. File by the name '<name>' already exists.
*/ 	        
For more details click Exception
String name = "TextFile007";
String filePath = "Local file path";
String description = "TextFile_123";						

Upload upload = uploadService.uploadFile(name,filePath,UploadFileType.IMAGE,description); /* returns the Upload object. */  
ArrayList<Upload.File> fileList =  upload.getFileList();  
for(Upload.File file : fileList)
{
	System.out.println("File Name is " + file.getName());
	System.out.println("File Type is " + file.getType());
	System.out.println("File Url is " + file.getUrl());
	System.out.println("File Description is " + file.getDescription());
}
String jsonResponse = upload.toString(); /* returns the response in JSON format. (as shown below)*/     
{
    "app42": {
        "response": {
            "success": true,
            "upload": {
                "files": {
                    "file": {
                        "name": "TextFile007",
                        "type": "TXT",
                        "url": "http://XXXX.txt",
                        "tinyUrl": "http://tinyurl.com/XXXX",
                        "description": "TextFile_123"
                    }
                }
            }
        }
    }
}
public Upload getAllFiles() throws App42Exception

Gets all the files for the App.

Parameters:

N/A

Returns:

Upload object

Response: Upload Object

Exception:

The method throws the following exception with the error code.
/*
2101 - NOT FOUND - Files do not exist. 
*/ 		        
For more details click Exception
Upload upload = uploadService.getAllFiles(); /* returns the Upload object. */  
ArrayList<Upload.File> fileList =  upload.getFileList();  
for(Upload.File file : fileList)
{
	System.out.println("File Name is " + file.getName());
	System.out.println("File Type is " + file.getType());
	System.out.println("File Url is " + file.getUrl());
	System.out.println("File Description is " + file.getDescription()); 
}
String jsonResponse = upload.toString(); /* returns the response in JSON format. (as shown below)*/    
{
    "app42": {
        "response": {
            "success": true,
            "upload": {
                "files": {
                    "file": [
                        {
                            "name": "TextFile01",
                            "type": "TXT",
                            "url": "http://XXXX.txt",
							"tinyUrl": "http://tinyurl.com/XXXX",
                            "description": "TextFile_123"
                        },
                        {
                            "name": "TextFile007",
                            "type": "TXT",
                            "url": "http://XXXX.txt",
							"tinyUrl": "http://tinyurl.com/XXXX",
                            "description": "TextFile_123"
                        }
                    ]
                }
            }
        }
    }
}
public App42Response getAllFilesCount() throws App42Exception

Gets count of all the files for the App

Parameters:

N/A

Returns:

App42Response object

Response: App42Response Object

For more details click Exception
App42Response response = uploadService.getAllFilesCount(); /* returns the App42Response objects. */
boolean  success = response.isResponseSuccess();
int totalRecords = response.getTotalRecords();
String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/     
{
    "app42": {
        "response": {
            "success": true,
            "totalRecords": 3
        }
    }
}
public Upload getAllFiles(int max, int offset) throws App42Exception

Gets all the files By Paging for the App

Parameters:

max - Maximum number of records to be fetched
offset - From where the records are to be fetched

Returns:

Upload object

Response: Upload Object

Exception:

The method throws the following exception with the error code.
/*
2106 - NOT FOUND - The number of files are less than the specified offset : <offset>.
*/ 	    
For more details click Exception
int max = 1;
int offset = 0;  
						
Upload upload = uploadService.getAllFiles(max,offset); /* returns the Upload object. */  
ArrayList<Upload.File> fileList =  upload.getFileList();  
for(Upload.File file : fileList)
{
	System.out.println("File Name is " + file.getName());
	System.out.println("File Type is " + file.getType());
	System.out.println("File Url is " + file.getUrl());
	System.out.println("File Description is " + file.getDescription());
}
String jsonResponse = upload.toString(); /* returns the response in JSON format. (as shown below)*/        
{
    "app42": {
        "response": {
            "success": true,
            "upload": {
                "files": {
                    "file": {
                        "name": "FILEName123",
                        "userName": "Nick",
                        "type": "AUDIO",
                        "url": "http://XXXX.mp3",
						"tinyUrl": "http://tinyurl.com/XXXX",
                        "description": "desc"
                    }
                }
            }
        }
    }
}
public Upload getFileByName(String name) throws App42Exception

Gets the file based on file name.

Parameters:

name - The name of the file which has to be retrieved

Returns:

Upload object

Response: Upload Object

Exception:

The method throws the following exception with the error code.
/*
2103 - NOT FOUND - The file with the name '<name>' does not exist. 
*/ 		    
For more details click Exception
String name = "TextFile01";
						
Upload upload = uploadService.getFileByName(name); /* returns the Upload object. */  
ArrayList<Upload.File> fileList =  upload.getFileList();  
for(Upload.File file : fileList)
{
	System.out.println("File Name is " + file.getName());
	System.out.println("File Type is " + file.getType());
	System.out.println("File Url is " + file.getUrl());
	System.out.println("File Description is " + file.getDescription());
}
String jsonResponse = upload.toString(); /* returns the response in JSON format. (as shown below)*/   
{
    "app42": {
        "response": {
            "success": true,
            "upload": {
                "files": {
                    "file": {
                        "name": "TextFile01",
                        "type": "TXT",
                        "url": "http://XXXX.txt",
						"tinyUrl": "http://tinyurl.com/XXXX",
                        "description": "TextFile_123"
                    }
                }
            }
        }
    }
}
public Upload getFilesByType(UploadFileType uploadFileType) throws App42Exception

Get the files based on file type.

Parameters:

uploadFileType - Type of the file e.g. Upload.AUDIO, Upload.XML etc.

Returns:

Upload object

Response: Upload Object

Exception:

The method throws the following exception with the error code.
/*
2105 - NOT FOUND - The file with type '<type>' does not exist. 
*/ 		 
For more details click Exception
Upload upload = uploadService.getFilesByType(UploadFileType.IMAGE); /* returns the Upload object. */  
ArrayList fileList =  upload.getFileList();  
for(Upload.File file : fileList)
{
	System.out.println("File Name is " + file.getName());
	System.out.println("File Type is " + file.getType());
	System.out.println("File Url is " + file.getUrl());
	System.out.println("File Description is " + file.getDescription()); 
}
String jsonResponse = upload.toString(); /* returns the response in JSON format. (as shown below)*/       
{
    "app42": {
        "response": {
            "success": true,
            "upload": {
                "files": {
                    "file": [
                        {
                            "name": "TextFile01",
                            "type": "TXT",
                            "url": "http://XXXX.txt",
                            "tinyUrl": "http://tinyurl.com/XXXX",
                            "description": "TextFile_123"
                        },
                        {
                            "name": "TextFile007",
                            "type": "TXT",
                            "url": "http://XXXX.txt",
                            "tinyUrl": "http://tinyurl.com/XXXX",
                            "description": "TextFile_123"
                        }
                    ]
                }
            }
        }
    }
}
public App42Response getFilesCountByType(UploadFileType uploadFileType) throws App42Exception

Get the count of files based on file type.

Parameters:

uploadFileType - Type of the file e.g. Upload.AUDIO, Upload.XML etc.

Returns:

App42Response object

Response: App42Response Object

For more details click Exception
App42Response response = uploadService.getFilesCountByType(UploadFileType.AUDIO); /* returns the App42Response objects. */
boolean  success = response.isResponseSuccess();
int totalRecords = response.getTotalRecords();
String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/    
{
    "app42": {
        "response": {
            "success": true,
            "totalRecords": 3
        }
    }
}
public Upload getFilesByType(UploadFileType uploadFileType, int max, int offset) throws App42Exception

Get the files based on file type by Paging.

Parameters:

uploadFileType - Type of the file e.g. Upload.AUDIO, Upload.XML etc.
max - Maximum number of records to be fetched
offset - From where the records are to be fetched

Returns:

Upload object

Response: Upload Object

Exception:

The method throws the following exception with the error code.
/*
2108 - NOT FOUND - The number of files with type '<type>' are less than the specified offset : <offset>.
*/ 		       
For more details click Exception
int max = 1;
int offset = 0;						

Upload upload = uploadService.getFilesByType(UploadFileType.AUDIO,max,offset); /* returns the Upload object. */  
ArrayList<Upload.File> fileList =  upload.getFileList();  
for(Upload.File file : fileList)
{
	System.out.println("File Name is " + file.getName());
	System.out.println("File Type is " + file.getType());
	System.out.println("File Url is " + file.getUrl());
	System.out.println("File Description is " + file.getDescription()); 
}
String jsonResponse = upload.toString(); /* returns the response in JSON format. (as shown below)*/         
{
    "app42": {
        "response": {
            "success": true,
            "upload": {
                "files": {
                    "file": {
                        "name": "FILEName123",
                        "userName": "Nick",
                        "type": "AUDIO",
                        "url": "http://XXXX.mp3",
                        "tinyUrl": "http://tinyurl.com/XXXX",
                        "description": "desc"
                    }
                }
            }
        }
    }
}
public App42Response removeFileByName(String name) throws App42Exception

Removes the file based on file name.

Parameters:

name - The name of the file which has to be removed

Returns:

App42Response if deleted successfully

Response: App42Response Object

Exception:

The method throws the following exception with the error code.
/*
2103 - NOT FOUND - The file with the name {name} does not Exist
*/ 		       
For more details click Exception
String name = "TextFile007";
						
App42Response response = uploadService.removeFileByName(name); /* returns the App42Response object. */
boolean  success = response.isResponseSuccess();
String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/      
{
    "app42": {
        "response": {
            "success": true,
            "upload": {
                "files": {
                    "file": {
                        "name": "TextFile007",
                        "userName": "Nick",
                        "type": "TXT",
                        "url": "http://XXXX.txt",
                        "tinyUrl": "http://tinyurl.com/XXXX",
                        "description": "TextFile_098"
                    }
                }
            }
        }
    }
}
public App42Response removeAllFiles() throws App42Exception

Removes all the files for the App

Parameters:

N/A

Returns:

App42Response if deleted successfully

Response: App42Response Object

Exception:

The method throws the following exception with the error code.
/*
2104 - NOT FOUND - There are no files to remove.
*/ 		     
For more details click Exception
App42Response response = uploadService.removeAllFiles(); /* returns the App42Response object. */
boolean  success = response.isResponseSuccess();
String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/       
{
    "app42": {
        "response": {
            "success": true,
            "upload": {
                "files": {
                    "file": [
                        {
                            "name": "FILEName01844",
                            "userName": "Nick",
                            "type": "AUDIO",
                            "url": "http://XXXX.mp3",
                            "tinyUrl": "http://tinyurl.com/XXXX",
                            "description": "Audio123"
                        },
                        {
                            "name": "FILEName01755",
                            "userName": "Nick",
                            "type": "AUDIO",
                            "url": "http://YYYY.mp3",
                            "tinyUrl": "http://tinyurl.com/XXXX",
                            "description": "Audio123"
                        }
                    ]
                }
            }
        }
    }
}
public Upload uploadFileForUser(String name, String userName, String filePath, UploadFileType fileType, String description) throws App42Exception

Uploads file on the cloud.

Parameters:

name - The name for the file which has to be saved. It is used to retrieve the file
userName - The name for the user for which file has to be saved.
filePath - The local path for the file
fileType - The type of the file. File can be either Audio, Video, Image, Binary, Txt, xml, json, csv or other Use the static constants e.g. Upload.AUDIO, Upload.XML etc.
description - Description of the file to be uploaded.

Returns:

Upload object

Response: Upload Object

Exception:

The method throws the following exception with the error code.
/*
2100 - BAD REQUEST - The request parameters are invalid. File by the name '<name>' already exists.
*/ 		      
For more details click Exception
String name = "File03";
String userName = "Nick";
String filePath = "Local file path";
String description = "TextFile_098";						

Upload upload = uploadService.uploadFileForUser(name,userName,filePath,UploadFileType.IMAGE,description); /* returns the Upload object. */  
ArrayList<Upload.File> fileList =  upload.getFileList();  
for(Upload.File file : fileList)
{
	System.out.println("File Name is " + file.getName());
	System.out.println("File Type is " + file.getType());
	System.out.println("File Url is " + file.getUrl());
	System.out.println("File Description is " + file.getDescription());
}
String jsonResponse = upload.toString(); /* returns the response in JSON format. (as shown below)*/   
{
    "app42": {
        "response": {
            "success": true,
            "upload": {
                "files": {
                    "file": {
                        "name": "File03",
                        "userName": "Nick",
                        "type": "TXT",
                        "url": "http://XXXX.txt",
                        "tinyUrl": "http://tinyurl.com/XXXX",
                        "description": "TextFile_098"
                    }
                }
            }
        }
    }
}
public Upload getFileByUser(String name, String userName) throws App42Exception

Gets the file based on Username.

Parameters:

name - The name of the file which has to be retrieved
userName - The name of the user for which file has to be retrieved

Returns:

Upload object

Response: Upload Object

Exception:

The method throws the following exception with the error code.
/*
2102 - NOT FOUND - Files for the user '<userName>' do not exist.
2103 - NOT FOUND - The file with the name '<name>' does not exist.
*/ 		       
For more details click Exception
String name = "File03";
String userName = "Nick";
					
Upload upload = uploadService.getFileByUser(name,userName); /* returns the Upload object. */  
ArrayList<Upload.File> fileList =  upload.getFileList();  
for(Upload.File file : fileList)
{
	System.out.println("File Name is " + file.getName());
	System.out.println("File Type is " + file.getType());
	System.out.println("File Url is " + file.getUrl());
	System.out.println("File Description is " + file.getDescription()); 
}
String jsonResponse = upload.toString(); /* returns the response in JSON format. (as shown below)*/        
{
    "app42": {
        "response": {
            "success": true,
            "upload": {
                "files": {
                    "file": {
                        "name": "File03",
                        "userName": "Nick",
                        "type": "TXT",
                        "url": "http://XXXX.txt",
                        "tinyUrl": "http://tinyurl.com/XXXX",
                        "description": "TextFile_098"
                    }
                }
            }
        }
    }
}
public Upload getAllFilesByUser(String userName) throws App42Exception

Get all the files based on user name.

Parameters:

userName - The name of the user for which file has to be retrieved

Returns:

Upload object

Response: Upload Object

Exception:

The method throws the following exception with the error code.
/*
2102 - NOT FOUND - Files for the user '<userName>' do not exist. 
*/ 		       
For more details click Exception
String userName = "Nick";

Upload upload = uploadService.getAllFilesByUser(userName); /* returns the Upload object. */  
ArrayList<Upload.File> fileList =  upload.getFileList();  
for(Upload.File file : fileList)
{
	System.out.println("File Name is " + file.getName());
	System.out.println("File Type is " + file.getType());
	System.out.println("File Url is " + file.getUrl());
	System.out.println("File Description is " + file.getDescription()); 
}
String jsonResponse = upload.toString(); /* returns the response in JSON format. (as shown below)*/     
{
    "app42": {
        "response": {
            "success": true,
            "upload": {
                "files": {
                    "file": [
                        {
                            "name": "File02",
                            "userName": "Nick",
                            "type": "IMAGE",
                            "url": "http://XXXX.jpg",
                            "tinyUrl": "http://tinyurl.com/XXXX",
                            "description": "Image_012"
                        },
                        {
                            "name": "File03",
                            "userName": "Nick",
                            "type": "TXT",
                            "url": "http://XXXX.txt",
                            "tinyUrl": "http://tinyurl.com/XXXX",
                            "description": "TextFile_098"
                        }
                    ]
                }
            }
        }
    }
}
public App42Response getAllFilesCountByUser(String userName) throws App42Exception

Gets the count of file based on user name.

Parameters:

userName - The name of the user for which count of the file has to be retrieved

Returns:

App42Response object

Response: App42Response Object

For more details click Exception
String userName = "Nick";
						
App42Response response = uploadService.getAllFilesCountByUser(userName); /* returns the App42Response objects. */
boolean  success = response.isResponseSuccess();
int totalRecords = response.getTotalRecords();
String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/  
{
    "app42": {
        "response": {
            "success": true,
            "totalRecords": 3
        }
    }
}
public Upload getAllFilesByUser(String userName, int max, int offset) throws App42Exception

Gets the file based on user name by Paging.

Parameters:

userName - The name of the user for which file has to be retrieved
max - Maximum number of records to be fetched
offset - From where the records are to be fetched

Returns:

Upload object

Response: Upload Object

Exception:

The method throws the following exception with the error code.
/*
2107 - NOT FOUND - The number of files for the user '<userName>' are less than the specified offset : <offset>.
*/ 		        
For more details click Exception
String userName = "Nick";
int max = 1;
int offset = 0;
					
Upload upload = uploadService.getAllFilesByUser(userName,max,offset); /* returns the Upload object. */  
ArrayList<Upload.File> fileList =  upload.getFileList();  
for(Upload.File file : fileList)
{
    System.out.println("File Name is " + file.getName());
	System.out.println("File Type is " + file.getType());
	System.out.println("File Url is " + file.getUrl());
	System.out.println("File Description is " + file.getDescription()); 
}
String jsonResponse = upload.toString(); /* returns the response in JSON format. (as shown below)*/   
{
    "app42": {
        "response": {
            "success": true,
            "upload": {
                "files": {
                    "file": {
                        "name": "FileName11",
                        "userName": "Nick",
                        "type": "IMAGE",
                        "url": "http://XXXX.jpg",
                        "tinyUrl": "http://tinyurl.com/XXXX",
                        "description": "Image123"
                    }
                }
            }
        }
    }
}
public App42Response removeFileByUser(String name, String userName) throws App42Exception

Removes the file based on file name and user name.

Parameters:

name - The name of the file which has to be removed
userName - The name of the user for which file has to be removed

Returns:

App42Response if deleted successfully

Response: App42Response Object

Exception:

The method throws the following exception with the error code.
/*
2102 - NOT FOUND - Files for the user '<userName>' do not exist.
2103 - NOT FOUND - The file with the name '<name>' does not exist. 
*/ 		        
For more details click Exception
String name = "File03";
String userName = "Nick";
						
App42Response response = uploadService.removeFileByUser(name, userName); /* returns the App42Response object. */
boolean  success = response.isResponseSuccess();
String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/  
{
    "app42": {
        "response": {
            "success": true,
            "upload": {
                "files": {
                    "file": {
                        "name": "File03",
                        "userName": "Nick",
                        "type": "TXT",
                        "url": "http://XXXX.txt",
                        "tinyUrl": "http://tinyurl.com/XXXX",
                        "description": "TextFile_098"
                    }
                }
            }
        }
    }
}
public App42Response removeAllFilesByUser(String userName) throws App42Exception

Removes the file based on user name.

Parameters:

userName - The name of the user for which file has to be removed

Returns:

App42Response if deleted successfully

Response: App42Response Object

Exception:

The method throws the following exception with the error code.
/*
2102 - NOT FOUND - Files for the user '<userName>' do not exist. 
*/ 		        
For more details click Exception
userName = "Nick";
						
App42Response response = uploadService.removeAllFilesByUser(userName); /* returns the App42Response object. */
boolean  success = response.isResponseSuccess();
String jsonResponse = response.toString(); /* returns the response in JSON format. (as shown below)*/     
{
    "app42": {
        "response": {
            "success": true,
            "upload": {
                "files": {
                    "file": [
                        {
                            "name": "File02",
                            "userName": "Nick",
                            "type": "TXT",
                            "url": "http://XXXX.txt",
							"tinyUrl": "http://tinyurl.com/XXXX",
                            "description": "Image_012"
                        },
                        {
                            "name": "File03",
                            "userName": "Billy",
                            "type": "TXT",
                            "url": "http://XXXX.txt",
							"tinyUrl": "http://tinyurl.com/XXXX",
                            "description": "Image_013"
                        }
                    ]
                }
            }
        }
    }
}
public Upload uploadFile(String name, InputStream inputStream, UploadFileType fileType, String description) throws App42Exception

Uploads file on the cloud via Stream.

Parameters:

name - The name for the file which has to be saved. It is used to retrieve the file
inputStream - Input Stream for the Photo that has to be added
fileType - The type of the file. File can be either Audio, Video, Image, Binary, Txt, xml, json, csv or other Use the static constants e.g. Upload.AUDIO, Upload.XML etc.
description - Description of the file to be uploaded.

Returns:

Upload object

Response: Upload Object

For more details click Exception
String name = "TextFile007";
String imagePath = "Local file path";
String description = "TextFile_123";						
FileInputStream fileInputStream = null;

try
{
	fileInputStream = new FileInputStream(imagePath);
}
catch (FileNotFoundException e) 
{
	e.printStackTrace();
}
Upload upload = uploadService.uploadFile(name,fileInputStream,UploadFileType.IMAGE,description); /* returns the Upload object. */  
ArrayList<Upload.File> fileList =  upload.getFileList();  
for(Upload.File file : fileList)
{
	System.out.println("File Name is " + file.getName());
	System.out.println("File Type is " + file.getType());
	System.out.println("File Url is " + file.getUrl());
	System.out.println("File Description is " + file.getDescription());
}
String jsonResponse = upload.toString(); /* returns the response in JSON format. (as shown below)*/       
{
    "app42": {
        "response": {
            "success": true,
            "upload": {
                "files": {
                    "file": {
                        "name": "TextFile007",
                        "type": "TXT",
                        "url": "http://XXXX.txt",
                        "tinyUrl": "http://tinyurl.com/XXXX",
                        "description": "TextFile_123"
                    }
                }
            }
        }
    }
}
public Upload uploadFileForUser(String name, String userName, InputStream inputStream, UploadFileType fileType, String description) throws App42Exception

Uploads file for the user on the cloud via Stream.

Parameters:

name - The name for the file which has to be saved. It is used to retrieve the file
userName - The name for the user for which file has to be saved.
inputStream - Input Stream for the Photo that has to be added
fileType - The type of the file. File can be either Audio, Video, Image, Binary, Txt, xml, json, csv or other Use the static constants e.g. Upload.AUDIO, Upload.XML etc.
description - Description of the file to be uploaded.

Returns:

Upload object

Response: Upload Object

For more details click Exception
String name = "File03";
String userName = "Nick";
String imagePath = "Local file path";
String description = "TextFile_098";						
FileInputStream fileInputStream = null;

try
{
	fileInputStream = new FileInputStream(imagePath);
} 
catch (FileNotFoundException e) 
{
	e.printStackTrace();
}						
Upload upload = uploadService.uploadFileForUser(name,userName,fileInputStream,UploadFileType.IMAGE,description); /* returns the Upload object. */  
ArrayList<Upload.File> fileList =  upload.getFileList();  
for(Upload.File file : fileList)
{
	System.out.println("File Name is " + file.getName());
	System.out.println("File Type is " + file.getType());
	System.out.println("File Url is " + file.getUrl());
	System.out.println("File Description is " + file.getDescription());
}
String jsonResponse = upload.toString(); /* returns the response in JSON format. (as shown below)*/   
{
    "app42": {
        "response": {
            "success": true,
            "upload": {
                "files": {
                    "file": {
                        "name": "File03",
                        "userName": "Nick",
                        "type": "TXT",
                        "url": "http://XXXX.txt",
                        "tinyUrl": "http://tinyurl.com/XXXX",
                        "description": "TextFile_098"
                    }
                }
            }
        }
    }
}