The Cloud Manager classes have methods to list the contents of a folder, create a folder, delete a file or folder, and rename a file. In most cases this code suffices to develop a nice app, but if we want to transfer files (and folders), we need to use the Transfer class.
This class is used from all Cloud Services, and it has only one method. We create an instance of this class by calling the constructor:
RTransfer *rTransfer = [[RTransfer alloc]initWithUploadPath:upPath andSourceManager:sManager andDestinationManager:dManager andFileList:fileLists];
- upPath[NSString]: Is the rItem.path of the current folder. This is needed only when we want to transfer a file(s) into a folder. It can be empty string if we want to delete a file
- sManager[RManager]: The source RManager. This is the Cloud Service that the selected files will be copied from
- dManager[RManager]: The destination RManager. This is the Cloud Service that the selected files will be copied to
- fileLists[ArrayList[RItem]]: The list of selected files.
The action that will be performed on a file is determined by the value of the actionToBePerformed property. Thus, we can use an instance of the RTransfer class to either delete a file or copy a file. It is OK if the fileLists variable contains files with different values for the actionToBePerformed property.
Once we have the instance of the RTransfer class, we call the method start to transfer the files:
The RTransfer class uses two blocks to inform us about the progress and when the process is completed:
- (^isCompleted)(RTransfer *owner, NSString *error): This block is called when the process is completed. This means that all files that were in the fileLists array are transferred (deleted or copied). If there was a problem, the error variable inform us about the problem
- (^progressBlock)(RTransferProgress *progress): This block is called to inform us about the progress: Either of the file or of the entire process. The action property of the progress variable can take the following values:
- ttaFileName: The process to transfer a file is started. The property message of the progress variable is the name of the file
- ttaFileProgress: The progress of the file. The properties total and progress of the progress variable denote the bytes that are transferred and how many more are left to be transferred.
In order to transfer files from one Cloud Manager to another we need an instance of the RTransfer class. Once we create that instance, we call the start method. Then RTransfer instance calls the downloadFile and uploadLocalFile methods on the Cloud Managers to transfer the selected files. The two blocks of the RTransfer class will inform us about the progress and the status.