About File And Folder Operations

About File and Folder Operations

Contents

File Download

Call downloadFile to download a file from a user’s Personal Cloud Storage account. File is downloaded at the downloadPath location.

  1. Add Cloud SDK for Android to an existing or a new Android project.
  2. Initialize the CloudAPI class object with the application key, secret and the callback URL you obtained from the ThingSpace portal.
  3. Authorize the application by calling CloudAPI#authorize().
  4. Call getFullview or search method to obtain information on files stored in the user’s Personal Cloud Storage.
  5. Perform File Download using this code sample.

Code Sample

FullviewItem fullviewItem = (FullviewItem) itemList.getItem(position);
File sdcard = Environment.getExternalStorageDirectory();
File folder = new File(sdcard.getAbsoluteFile(), "DemoApp");
folder.mkdir();
try {
    boolean downloadSuccess = cloudAPI.downloadFile(context, fullviewItem.getParentPath(), fullviewItem.getName(), folder.getAbsolutePath());
    Log.d("Download", downloadSuccess ? "File downloaded": "File download failed");
} catch (CloudAPIException cloudAPIException) {
    if (cloudAPIException.getCode() == CloudAPIException.ErrorCode.USER_UNAUTHORIZED) {
        Log.d("Download", "User not authorized, please call CloudAPI#authorize()");
    }
}

File Upload

Call uploadFile method to upload files to a folder in a user’s Personal Cloud Storage account.

NOTE: You cannot perform uploadFile operatioin on a virtual folder.

  1. Add Cloud SDK for Android to an existing or a new Android project.
  2. Initialize the CloudAPI class object with the application key, secret and the callback URL you obtained from the ThingSpace portal.
  3. Authorize the application by calling CloudAPI#authorize().
  4. Call getMetadata method to obtain paths of the folders stored in the user’s Personal Cloud Storage. Use the path of an existing folder as the destinationFolderPath to upload the file to an existing folder. If a folder in the destination folder does not exist, a call to uploadFile API will create that folder.
  5. Perform file upload using this code sample.

Code Sample

try {
	boolean uploadSuccess = cloudAPI.uploadFile(context, destinationFolderPath, fileName, filePath);
	Log.d ("Upload", uploadSuccess ? "File uploaded" : "File upload failed");
} catch (CloudAPIException cloudAPIException) {
	if (cloudAPIException.getCode() == CloudAPIException.ErrorCode.USER_UNAUTHORIZED) {
		Log.d("Upload", "User not authorized, please call CloudAPI#authorize()");
	} else if (cloudAPIException.getCode() == CloudAPIException.ErrorCode.ERROR_FILE_ALREADY_EXIST) {
		Log.d("Upload", "File already exist");
	}
}

Fullview

Call fullview to retrieve all files and folders stored in a user’s Personal Cloud Storage account.

  1. Add Cloud SDK for Android to an existing or a new Android project.
  2. Initialize the CloudAPI class object with the application key, secret and the callback URL you obtained from the ThingSpace portal.
  3. Authorize the application by calling CloudAPI#authorize().
  4. Retrieve information on all files and folders in the user’s Personal Cloud Storage account using the code sample below.

Code Sample

try {
    ItemList<FullviewItem> itemListFullview = cloudAPI.fullview(context);
    for (int i=0; i<itemListFullview.getCount(); i++) {
		FullviewItem fullviewItem = itemListFullview.getItem(i);
        Log.d("Fullview", "Name: " + fullviewItem.getName());
	}
} catch (CloudAPIException cloudAPIException) {
    if (cloudAPIException.getCode() == CloudAPIException.ErrorCode.USER_UNAUTHORIZED) {
        Log.d("Fullview", "User not authorized, please call CloudAPI#authorize()");
    }
}

Thumbnails

Call getThumbnailToStream to retrieve thumbnails for files stored in a user’s Personal Cloud Storage account.

See Also:

  1. Add Cloud SDK for Android to an existing or a new Android project.
  2. Initialize the CloudAPI class object with the application key, secret and the callback URL you obtained from the ThingSpace portal.
  3. Authorize the application by calling CloudAPI#authorize().
  4. Use the code sample below to retrieve thumbnails for a specified file.

Code Sample

try {
    FileOutputStream fileOutputStream = new FileOutputStream("cache location");
    cloudAPI.getThumbnailToStream(context, data, fileOutputStream);
    Bitmap bitmap = BitmapFactory.decodeFileDescriptor(fileOutputStream.getFD());
} catch (CloudAPIException cloudAPIException) {
    if (cloudAPIException.getCode() == CloudAPIException.ErrorCode.USER_UNAUTHORIZED) {
		Log.d("Get Thumbnail", "User not authorized, please call CloudAPI#authorize()");
    }
}

Copyright © 2015-2017, Verizon and/or its Licensors. All rights reserved.