Previous Next

StorageService Introduction

The 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 Adapters

The 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.

Exemple #1 Using the StorageService Factory

$storage = Zend_Cloud_StorageService_Factory::getAdapter(array(
    Zend_Cloud_StorageService_Factory::STORAGE_ADAPTER_KEY => 'Zend_Cloud_StorageService_Adapter_S3',
    Zend_Cloud_StorageService_Adapter_S3::AWS_ACCESS_KEY   => $amazonKey,
    Zend_Cloud_StorageService_Adapter_S3::AWS_SECRET_KEY   => $amazonSecret,
));

StorageService Adapter Options

Zend_Cloud_StorageService_Adapter_S3 options
Option key Description Used in Required Default
aws_accesskey Amazon AWS access key Constructor Yes None
aws_secretkey Amazon AWS secret key Constructor Yes None
bucket_name The name of the S3 bucket for this item Used in the constructor to set the default bucket for the instantiated service. This option can also be specified in any of the item access operations. Yes None
bucket_as_domain Indicates that the bucket name is part of the domain name Used in constructor to set the default behavior for the instantiated service. This option can also be specified in any of the item access operations. No False
metadata Array of metadata to associate with the item storeItem() No None
fetch_stream Indicates whether the response is stream, and not a string

Note:

See the Zend_Service_Amazon_S3 documentation for more about handling streamed responses)

fetchItem() No False
http_adapter HTTP adapter to use in all access operations Constructor No Zend_Http_Client_Adapter_Socket
Zend_Cloud_StorageService_Adapter_WindowsAzure options
Option key Description Used in Required Default
storage_accountname Windows Azure account name Constructor Yes None
storage_accountkey Windows Azure account key Constructor Yes None
storage_container Container to use for this storage object Constructor Yes None
storage_host Windows Azure access host Constructor Yes blob.core.windows.net
storage_proxy_host Proxy hostname Constructor No None
storage_proxy_port Proxy port Constructor No 8080
storage_proxy_credentials Proxy credentials Constructor No None
http_adapter HTTP adapter to use in all access operations Constructor No Zend_Http_Client_Adapter_Socket
returntype How to return the results.
  • For fetchItem():

    RETURN_STRING

    Return the data as strings.

    RETURN_PATH

    save data on disk in temp file, return path name

    RETURN_STREAM

    Default: Return the data as stream

  • For listItems():

    RETURN_NAMES

    return the list of item names (default)

    RETURN_LIST

    return the list of WindowsAzure objects

fetchItem(), listItems() No RETURN_STREAM for fetchItem(); RETURN_NAMES for listItems()
return_path Return path. This is the URL that can be used to access the item after it has been uploaded. fetchItem() No System tmp directory
return_openmode fopen() mode used to open the file for saving data fetchItem() No 'r'
Zend_Cloud_StorageService_Adapter_Nirvanix options
Option key Description Used in Required Default
auth_username Nirvanix user name Constructor Yes None
auth_password Nirvanix password Constructor Yes None
auth_accesskey Nirvanix access key Constructor Yes None
http_adapter HTTP adapter to use in all access operations Constructor No Zend_Http_Client_Adapter_Socket
remote_directory Nirvanix directory to use Constructor (mandatory) Yes None
Zend_Cloud_StorageService_Adapter_Filesystem options
Option key Description Used in Required Default
local_directory Local directory where the files will be stored Constructor No System tmp directory

Basic concepts

Different 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.

Exceptions

If 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 item

storeItem() method is used to upload or otherwise add files to the storage provider.

Exemple #2 Storing an item

$data = file_get_contents('/my/local/dir/picture.jpg');
$returnedData = $storage->storeItem('/my/remote/path/picture.jpg', $data);

An optional third parameter describes service-specific options.

Exemple #3 Storing an item with options

$data = file_get_contents("/my/local/dir/picture.jpg");

// Use S3 bucket: myBucket
// Make this item publicly readable
$returnedData = $storage->storeItem(
    '/my/remote/path/picture.jpg', 
    $data, 
    array(
        Zend_Cloud_StorageService_Adapter_S3::BUCKET_NAME => "myBucket",
        Zend_Cloud_StorageService_Adapter_S3::METADATA    => array(
            Zend_Service_Amazon_S3::S3_ACL_HEADER => Zend_Service_Amazon_S3::S3_ACL_PUBLIC_READ,
        )
    )
);

For service adapters that support streaming, data can also be a PHP stream (i.e. opened file).

Fetch an item

The fetchItem() operation retrieves an item from the storage.

Exemple #4 Fetching an item

$returnedData = $storage->fetchItem("/my/remote/path/picture.jpg");
file_put_contents($localFilePath, $returnedData);

Delete an item

The deleteItem() operation removes an item from the storage service.

Exemple #5 Deleting an item

$storage->deleteItem("/my/remote/path/picture.jpg");

Copy an item

The copyItem() operation creates a copy of the item in the storage.

Note:

Not all services support copying natively. If this is the case, the adapter will simulate the operation, fetching the item and storing it under the target path.

Exemple #6 Copying an item

$storage->copyItem(
    '/my/remote/path/picture.jpg', 
    '/anothor/remote/dir/picturecopy.jpg'
);

Move an item

The moveItem() operation moves an item from one key (or directory) to another.

Note:

Not all services support moving natively. If this is the case the adapter will simulate the operation, fetching the item, storing it under the target path, then deleting the original file.

Exemple #7 Moving an item

$storage->moveItem(
    '/my/remote/path/picture.jpg',
    '/anothor/remote/dir/newpicture.jpg'
);

Rename an item

The renameItem() operation changes the item name. For some services, this operation may be equivalent to moving to its original directory with a new name.

Exemple #8 Renaming an item

$storage->renameItem('/my/remote/path/picture.jpg', 'newpicture.jpg');

List items

To list the items stored in the specified path, use the listItems() method. The method returns a list of names identifying matching remote items.

Exemple #9 List items

$objects = $storage->listItems('/my/remote/path/');
foreach ($objects as $objname) {
    echo "Found: $objname\n";
}

Fetching metadata

Some services store a set of key-value pairs along with the item as metadata. Use the fetchMetadata() method to retrieve an item's metadata.

Exemple #10 Fetching metadata

$data = $storage->fetchMetadata('/my/remote/path/picture.jpg');
foreach ($data as $key => $value) {
    echo "Metadata $key: $value\n";
}

Store metadata

Depending 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.

Exemple #11 Storing metadata

$data = $storage->storeMetadata('/my/remote/path/picture.jpg', array(
    'type'     => 'JPEG',
    'category' => 'Portrait',
));

Delete metadata

The deleteMetadata() method removes all user-supplied metadata from an item.

Note:

Not all services support removing metadata.

Exemple #12 Deleting metadata

$storage->deleteMetadata("/my/remote/path/picture.jpg");

Accessing concrete adapters

Sometimes 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.

Note:

Accessing the underlying adapter breaks portability among services, so it should be reserved for exceptional circumstances only.

Exemple #13 Using a concrete adapter

// the Simple Cloud Storage API doesn't support "clean bucket" operation
// the concrete adapter can be used to access this feature 
$s3 = $storage->getClient();
$s3->cleanBucket("oldBucket");
Previous Next
Introduction au Zend Framework
Présentation
Installation
Apprendre Zend Framework
Démarrez rapidement avec Zend Framework
Zend Framework & Introduction MVC
Créer votre projet
Créer une layout
Créer un modèle et une table en base de données
Créer un formulaire
Félicitations !
Chargement automatique avec Zend Framework
Introduction
Architecture et buts
Utilisation de base de l'autoloader
Auto-chargement de resources
Conclusion
Les plugins dans Zend Framework
Introduction
Utiliser des Plugins
Conclusion
Bien démarrer avec Zend_Layout
Introduction
Utiliser Zend_Layout
Zend_Layout: Conclusions
Bien démarrer avec Zend_View
Introduction
Utilisation de base des Placeholders
Placeholders standards
View Placeholders: Conclusion
Bien comprendre et utiliser les décorateurs Zend Form
Introduction
Les bases des décorateurs
Chainer les décorateurs
Rendu individuel des décorateurs
Créer et rendre des éléments composites
Conclusion
Bien démarrer avec Zend_Session, Zend_Auth, et Zend_Acl
Fabrique une application Multi-Utilisateurs avec Zend Framework
Gérer les sessions dans ZF
Authentification d'utilisateurs dans Zend Framework
Fabriquer un système de gestion d'autorisations avec Zend Framework
Bien démarrer avec Zend_Search_Lucene
Introduction à Zend_Search_Lucene
Structure d'index Lucene
Ouverture et création d'index
Indexation
Recherche
Requêtes supportées
Pagination de résultat de recherche
Bien démarrer avec Zend_Paginator
Introduction
Exemples simples
Contrôles de la pagination et styles de défilement
Assembler le tout
Guide de référence Zend Framework
Zend_Acl
Introduction
Affiner les Contrôles d'Accès
Utilisation avancée
Zend_Amf
Introduction
Zend_Amf_Server
Zend_Application
Introduction
Zend_Application démarrage rapide
Théorie générale
Exemples
Fonctionnalités principales
Plugins de ressources disponibles
Zend_Auth
Introduction
Authentification avec une table de base de données
Authentification "Digest"
Adaptateur d'authentification HTTP
LDAP Authentication
Authentification OpenID
Zend_Barcode
Introduction
Création de code-barres avec la classe Zend_Barcode
Zend_Barcode Objects
Zend_Barcode Renderers
Zend_Cache
Introduction
Aspect théorique
Les frontends Zend_Cache
Les backends Zend_Cache
Le gestionnaire de Cache
Zend_Captcha
Introduction
Opération Captcha
Adaptateurs CAPTCHA
SimpleCloud API: Zend_Cloud
Document Service Introduction
Queue Service Introduction
StorageService Introduction
Zend_CodeGenerator
Introduction
Exemples Zend_CodeGenerator
Zend_CodeGenerator Réference
Zend_Config
Introduction
Aspect théorique
Zend_Config_Ini
Zend_Config_Json
Zend_Config_Xml
Zend_Config_Yaml
Zend_Config_Writer
Zend_Config_Writer
Zend_Console_Getopt
Introduction
Déclarer les règles Getopt
Extraire les options et les arguments
Configurer Zend_Console_Getopt
Zend_Controller
Zend_Controller - Démarrage rapide
Fondations de Zend_Controller
Le contrôleur frontal (Front Controller)
L'objet Requête
Routeur Standard
Le distributeur
Contrôleurs d'action
Aides d'action (Helper)
Objet de réponse
Plugins
Utilisation de conventions de dossiers modulaires
Exceptions avec MVC
Zend_Currency
Introduction à Zend_Currency
Utiliser Zend_Currency
Options des monnaies
Qu'est ce qui définit une monnaie?
Où est le symbole monnétaire?
A quoi ressemble une monnaie?
Travailler avec les valeurs des monnaies (les montants)
Calculs avec les monnaies
Echanger (convertir) des monnaies
Informations complémentaires pour Zend_Currency
Zend_Date
Introduction
Aspect théorique
Méthodes de base
Zend_Date API Overview
Créer des dates
Constants for General Date Functions
Exemples concrets
Zend_Db
Zend_Db_Adapter
Zend_Db_Statement
Zend_Db_Profiler
Zend_Db_Select
Zend_Db_Table
Zend_Db_Table_Row
Zend_Db_Table_Rowset
Relations Zend_Db_Table
Zend_Db_Table_Definition
Zend_Debug
Afficher des informations
Zend_Dojo
Introduction
Zend_Dojo_Data: dojo.data Envelopes
Les aides de vues Dojo
Les éléments de formulaire et les décorateurs Dojo
Zend_Dojo build layer support
Zend_Dom
Introduction
Zend_Dom_Query
Zend_Exception
Utiliser les exceptions
Utilisation classique
Exceptions précédentes
Zend_Feed
Introduction
Importer des flux
Obtenir des flux à partir de pages Web
Consommer un flux RSS
Consommer un flux Atom
Consommer une entrée Atom particulière
Modifier la structure du flux ou des entrées
Classes personnalisées pour les flux et entrées
Zend_Feed_Reader
Zend_Feed_Writer
Zend_Feed_Pubsubhubbub
Zend_File
Zend_File_Transfer
Validateurs pour Zend_File_Transfer
Filtres pour Zend_File_Transfer
Zend_Filter
Introduction
Classes de filtre standards
Chaînes de filtrage
Écriture de filtres
Zend_Filter_Input
Zend_Filter_Inflector
Zend_Form
Zend_Form
Zend_Form démarrage rapide
Creating Form Elements Using Zend_Form_Element
Creating Forms Using Zend_Form
Créer un visuel personnalisé en utilisant Zend_Form_Decorator
Les éléments standards fournis avec Zend Framework
Décorateurs standards fournis avec Zend Framework
Internationaliser un formulaire Zend_Form
Advanced Zend_Form Usage
Zend_Gdata
Introduction
Authentification par procédé AuthSub
Using the Book Search Data API
Authentification avec ClientLogin
Using Google Calendar
Using Google Documents List Data API
Using Google Health
Using Google Spreadsheets
Using Google Apps Provisioning
Using Google Base
Utilisation des albums Web Picasa
Using the YouTube Data API
Attraper les exceptions Gdata
Zend_Http
Introduction
Zend_Http_Client - Utilisation avancée
Zend_Http_Client - Adaptateurs de connexion
Zend_Http_Cookie and Zend_Http_CookieJar
Zend_Http_Response
Zend_Http_UserAgent
The UserAgent Device Interface
The UserAgent Features Adapter
The WURFL UserAgent Features Adapter
The DeviceAtlas UserAgent Features Adapter
The TeraWurfl UserAgent Features Adapter
The UserAgent Storage Interface
The Session UserAgent Storage Adapter
Zend_InfoCard
Introduction
Zend_Json
Introduction
Utilisation de base
Utilisation avancée de Zend_Json
XML to JSON conversion
Zend_Json_Server - JSON-RPC server
Zend_Layout
Introduction
Zend_Layout - Démarrage rapide
Zend_Layout options de configuration
Zend_Layout, utilisation avancée
Zend_Ldap
Introduction
API overview
Scénarios d'utilisation
Outils
Accès à l'arbre LDAP de manière orientée objet avec Zend_Ldap_Node
Récupérer des informations depuis un serveur LDAP
Serialiser des données LDAP depuis/vers LDIF
Zend_Loader
Charger les fichiers et les classes dynamiquement
L'autoloader
Autoloaders de ressources
Chargeur de Plugins
Zend_Locale
Introduction
Using Zend_Locale
Normalization and Localization
Working with Dates and Times
Supported locales
Zend_Log
Présentation
Rédacteurs (Writers)
Formateurs (mise en forme)
Filtres
Utiliser la fabrique pour créer des logs
Zend_Mail
Introduction
Envoyer des courriels en utilisant SMTP
Envoyer plusieurs courriels par connexion SMTP
Utiliser différents transports
Courriel HTML
Fichiers joints
Ajouter des destinataires
Contrôler les limites MIME
En-têtes additionnels
Jeux de caractères
Encodage
Authentification SMTP
Sécuriser les transports SMTP
Lire des courriels
Zend_Markup
Introduction
Guide de démarrage avec Zend_Markup
Analyseurs Zend_Markup (parsers)
Moteurs de rendu Zend_Markup
Zend_Measure
Introduction
Création d'une mesure
Récupérer des mesures
Manipuler des mesures
Types de mesures
Zend_Memory
Présentation
Manager de mémoire
Objet mémoire
Zend_Mime
Zend_Mime
Zend_Mime_Message
Zend_Mime_Part
Zend_Navigation
Introduction
Pages
Containers
Zend_Oauth
Introduction to OAuth
Zend_OpenId
Introduction
Zend_OpenId_Consumer Basics
Zend_OpenId_Provider
Zend_Paginator
Introduction
Utilisation
Configuration
Utilisation avancée
Zend_Pdf
Introduction
Créer et charger des documents PDF
Sauvegarder les changement dans un document PDF
Les pages d'un document
Dessiner
Interactive Features
Informations du document et métadonnées
Exemple d'utilisation du module Zend_Pdf
Zend_ProgressBar
Zend_ProgressBar
Zend_Queue
Introduction
Example usage
Framework
Adapters
Customizing Zend_Queue
Stomp
Zend_Reflection
Introduction
Zend_Reflection Exemples
Réference de Zend_Reflection
Zend_Registry
Utiliser le registre
Zend_Rest
Introduction
Zend_Rest_Client
Zend_Rest_Server
Zend_Search_Lucene
Vue d'ensemble
Créer des index
Chercher dans un index
Langage de requêtes
API de construction de requêtes
Jeu de caractères
Extensibilité
Agir avec Lucene Java
Avancé
Bonnes pratiques
Zend_Serializer
Introduction
Zend_Serializer_Adapter
Zend_Server
Introduction
Zend_Server_Reflection
Zend_Service
Introduction
Zend_Service_Akismet
Zend_Service_Amazon
Zend_Service_Amazon_Ec2
Zend_Service_Amazon_Ec2: Instances
Zend_Service_Amazon_Ec2: Windows Instances
Zend_Service_Amazon_Ec2: Reserved Instances
Zend_Service_Amazon_Ec2: CloudWatch Monitoring
Zend_Service_Amazon_Ec2: Amazon Machine Images (AMI)
Zend_Service_Amazon_Ec2: Elastic Block Storage (EBS)
Zend_Service_Amazon_Ec2: Elastic IP Addresses
Zend_Service_Amazon_Ec2: Keypairs
Zend_Service_Amazon_Ec2: Regions and Availability Zones
Zend_Service_Amazon_Ec2: Security Groups
Zend_Service_Amazon_S3
Zend_Service_Amazon_Sqs
Zend_Service_Audioscrobbler
Zend_Service_Delicious
Zend_Service_DeveloperGarden
Zend_Service_Ebay
Zend_Service_Ebay_Finding
Zend_Service_Flickr
Zend_Service_LiveDocx
Zend_Service_Nirvanix
Zend_Service_ReCaptcha
Zend_Service_ShortUrl
Zend_Service_Simpy
Zend_Service_SlideShare
Zend_Service_StrikeIron
Zend_Service_StrikeIron: Bundled Services
Zend_Service_StrikeIron: Advanced Uses
Zend_Service_Technorati
Zend_Service_Twitter
Zend_Service_WindowsAzure
Zend_Service_WindowsAzure_Storage_Blob
Zend_Service_WindowsAzure_Diagnostics_Manager
Zend_Service_WindowsAzure_Storage_Queue
Zend_Service_WindowsAzure_Storage_Table
Zend_Service_Yahoo
Zend_Session
Introduction
Usage basique
Utilisation avancée
Gestion générale de la session
Zend_Session_SaveHandler_DbTable
Zend_Soap
Zend_Soap_Server
Zend_Soap_Client
WSDL
Auto découverte
Zend_Tag
Introduction
Zend_Tag_Cloud
Zend_Test
Introduction
Zend_Test_PHPUnit
Zend_Test_PHPUnit_Db
Zend_Text
Zend_Text_Figlet
Zend_Text_Table
Zend_TimeSync
Introduction
Utiliser Zend_TimeSync
Zend_Tool
Using Zend_Tool On The Command Line
Extending Zend_Tool
Zend_Tool_Framework
Introduction
Using the CLI Tool
Architecture
Creating Providers to use with Zend_Tool_Framework
Shipped System Providers
Extending and Configuring Zend_Tool_Framework
Zend_Tool_Project
Introduction
Créer un projet
Fournisseurs de Zend_Tool_Project
Rouages internes de Zend_Tool_Project
Zend_Translate
Introduction
Adaptateurs pour Zend_Translate
Utiliser les adaptateurs de traduction
Creating source files
Additional features for translation
Notation des pluriels pour Translation
Zend_Uri
Zend_Uri
Zend_Validate
Introduction
Classes de validation standard
Chaînes de validation
Écrire des validateurs
Messages de validation
Zend_Version
Lire la version de Zend Framework
Zend_View
Introduction
Scripts de contrôleur
Scripts de vue
Aides de vue
Zend_View_Abstract
Zend_Wildfire
Zend_Wildfire
Zend_XmlRpc
Introduction
Zend_XmlRpc_Client
Zend_XmlRpc_Server
ZendX_Console_Process_Unix
ZendX_Console_Process_Unix
ZendX_JQuery
Introduction
ZendX_JQuery View Helpers
ZendX_JQuery Form Elements and Decorators
Configuration système requise par Zend Framework
Introduction
Notes de migration de Zend Framework
Zend Framework 1.10
Zend Framework 1.9
Zend Framework 1.8
Zend Framework 1.7
Zend Framework 1.6
Zend Framework 1.5
Zend Framework 1.0
Zend Framework 0.9
Zend Framework 0.8
Zend Framework 0.6
Convention de codage PHP de Zend Framework
Vue d'ensemble
Formatage des fichiers PHP
Conventions de nommage
Style de codage
Recommandation sur la documentation de Zend Framework
Présentation
Format des fichiers de documentation
Recommendations
Recommended Project Structure for Zend Framework MVC Applications
Overview
Recommended Project Directory Structure
Module Structure
Rewrite Configuration Guide
Guide de performance Zend Framework
Introduction
Chargement des classes
Performance de Zend_Db
Internationalisation (i18n) and Localisation (l10n)
View Rendering
Informations de copyright