Like any other of our modules, the CloudFile module provide a easy to use Interface.
So you are able to use the module within your own extensions without any major work.
I will guide you step by step to provide Cloud Storage functions:
1. You need to get a list of available Connections
$cloudFileModule = new CloudFile_Module_Model();
$connections = $cloudFileModule->getAvailableConnections();
This will return an array of configured connections, in the following format:
array {
0 =>
array (size=3)
'titel' => string 'ConnectionTitle'
'connectionid' => string 'Connection ID'
'image_16' => string 'URL to provider Image 16x16'
1 =>
array (size=3)
'titel' => string 'ConnectionTitle'
'connectionid' => string 'Connection ID'
'image_16' => string 'URL to provider Imagee 16x16'
2 =>
array (size=3)
'titel' => string 'ConnectionTitle'
'connectionid' => string 'Connection ID'
'image_16' => string 'URL to provider Image 16x16'
...
}
Use this list select connection ID you want to use.
2. Use the Connection
This is the important step, but is not much harder, then the first one.
You only need to understand the two systems:
There are hierarchical and ID based systems.
- Hierarchical file systems will with “real” file path, directories, subdirectories, …. Examples are FTP, Dropbox, Filesystem
- ID based systems, which use filepaths only to organize visual presentation, but works only with IDs. Every directory and file have a unique ID. A major example is Google Drive.
Because the CloudFile module supports both types, you will get a path and a key everytime you work with files and directories. Use both to be fully compatible to both systems.
2.1 Get Connection Object
$connection = \CloudFile\Connection::getAdapter($connection_id);
That’s all!
Now you have a object from your Adapter, which inherits from \CloudFile\Adapter\Base, and could work with the cloud storage.
Found all available methods here: https://redoonetworks.github.io/VtigerCRM-CloudFile-Developers/output/classes/CloudFile.Adapter.Base.html
Examples
Create a folder:
$connection->mkdir('New Folder Name');
Upload a file:
$connection->upload($localFilename, basename($localFilename));
This uploads the file from $localFilename into the current folder and same filename of the local file.