StorageService IntroductionThe storage service in the Simple Cloud API implements a basic interface for file storage on the cloud. The files have no internal structure as far as the service is concerned, and are identified by a string key that is analogous to a filepath on a filesystem. StorageService AdaptersThe interface Zend_Cloud_StorageService_Adapter defines methods that each concrete storage service adapter must implement. The following adapters are shipped with the Simple Cloud API:
To create the service object, call the static method Zend_Cloud_StorageService_Factory::getAdapter(), which accepts either an array or a Zend_Config object. The key named storage_adapter should specify the concrete adapter class. Adapter-specific keys may also be passed in this configuration parameter. Example #1 Using the StorageService Factory
StorageService Adapter Options
Basic conceptsDifferent cloud storage services use their own unique terminology to refer to document storage concepts. The SimpleCloud API defines a number of common concepts that are shared among all major providers. The storage service identifies files by string keys, which may be URL paths or another service-specific identifier. The items can be stored and retrieved using this key. Each item can have metadata associated with it. These metadata carry service-specific information about the item, such as size, type, permissions, etc. as defined in the adapter for that provider. ExceptionsIf some error occurs inside the storage service, a Zend_Cloud_StorageService_Exception is thrown. If the exception was caused by underlying service driver, you can use the getClientException() method to retrieve the original exception. Since different cloud providers implement different sets of services, some adapters do not implement certain features. In this case, the Zend_Cloud_OperationNotAvailableException exception is thrown. Store an itemstoreItem() method is used to upload or otherwise add files to the storage provider. Example #2 Storing an item
An optional third parameter describes service-specific options. Example #3 Storing an item with options
For service adapters that support streaming, data can also be a PHP stream (i.e. opened file). Fetch an itemThe fetchItem() operation retrieves an item from the storage. Example #4 Fetching an item
Delete an itemThe deleteItem() operation removes an item from the storage service. Example #5 Deleting an item
Copy an itemThe copyItem() operation creates a copy of the item in the storage.
Example #6 Copying an item
Move an itemThe moveItem() operation moves an item from one key (or directory) to another.
Example #7 Moving an item
Rename an itemThe renameItem() operation changes the item name. For some services, this operation may be equivalent to moving to its original directory with a new name. Example #8 Renaming an item
List itemsTo list the items stored in the specified path, use the listItems() method. The method returns a list of names identifying matching remote items. Example #9 List items
Fetching metadataSome services store a set of key-value pairs along with the item as metadata. Use the fetchMetadata() method to retrieve an item's metadata. Example #10 Fetching metadata
Store metadataDepending on the service, metadata can be supplied either when storing the item or with a separate request. In the latter case, use storeMetadata() to add or update this metadata. Example #11 Storing metadata
Delete metadataThe deleteMetadata() method removes all user-supplied metadata from an item.
Example #12 Deleting metadata
Accessing concrete adaptersSometimes it is necessary to retrieve the concrete adapter for the service that the Storage API is working with. This can be achieved by using the getAdapter() method.
Example #13 Using a concrete adapter
|