Zend_Service_WindowsAzure_Blob.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- EN-Revision: 19991 -->
  3. <!-- Reviewed: no -->
  4. <sect1 id="zend.service.windowsazure.storage.blob">
  5. <title>Zend_Service_WindowsAzure_Storage_Blob</title>
  6. <para>
  7. Blob Speicher speichert ein Set von Binären Daten. Blog Speicher bietet die folgenden drei
  8. Ressourcen an: den Speicher Account, Container und Blobs. Im eigenen Speicher Account bieten
  9. Container einen Weg um Sets von Blobs im Speicher Account zu organisieren.
  10. </para>
  11. <para>
  12. Blog Speicher wird von Windows Azure als <acronym>REST</acronym> API angeboten welcher von
  13. der Klasse <classname>Zend_Service_WindowsAzure_Storage_Blob</classname> umhüllt ist um ein
  14. natives PHP Interface zum Speicher Account zu bieten.
  15. </para>
  16. <sect2 id="zend.service.windowsazure.storage.blob.api">
  17. <title>API Beispiele</title>
  18. <para>
  19. Dieser Abschnitt zeigt einige Beispiele der Verwendung der Klasse
  20. <classname>Zend_Service_WindowsAzure_Storage_Blob</classname>. Andere Features sind im
  21. Download Paket vorhanden sowie in der detailierten API Dokumentation dieser Features.
  22. </para>
  23. <sect3 id="zend.service.windowsazure.storage.blob.api.create-container">
  24. <title>Erstellung einer Speicher Containers</title>
  25. <para>
  26. Bei Verwendung des folgenden Codes kann ein Speicher Container auf dem Development
  27. Speicher erstellt werden.
  28. </para>
  29. <example id="zend.service.windowsazure.storage.blob.api.create-container">
  30. <title>Erstellung eines Speicher Containers</title>
  31. <programlisting language="php"><![CDATA[
  32. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
  33. $result = $storageClient->createContainer('testcontainer');
  34. echo 'Der Name des Containers ist: ' . $result->Name;
  35. ]]></programlisting>
  36. </example>
  37. </sect3>
  38. <sect3 id="zend.service.windowsazure.storage.blob.api.delete-container">
  39. <title>Löschen eines Speicher Containers</title>
  40. <para>
  41. Bei Verwendung des folgenden Codes kann ein Blob Speicher Container vom Development
  42. Speicher entfernt werden.
  43. </para>
  44. <example id="zend.service.windowsazure.storage.blob.api.delete-container">
  45. <title>Löschen eines Speicher Containers</title>
  46. <programlisting role="php"><![CDATA[
  47. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
  48. $storageClient->deleteContainer('testcontainer');
  49. ]]></programlisting>
  50. </example>
  51. </sect3>
  52. <sect3 id="zend.service.windowsazure.storage.blob.api.storing-blob">
  53. <title>Speichern eines Blobs</title>
  54. <para>
  55. Bei Verwendung des folgenden Codes kann ein Blob zu einem Blog Speicher Container
  56. auf dem Development Speichers hochgeladen werden. Es ist zu beachten das der
  57. Container hierfür bereits vorher erstellt worden sein muss.
  58. </para>
  59. <example id="zend.service.windowsazure.storage.blob.api.storing-blob">
  60. <title>Speichern eines Blobs</title>
  61. <programlisting language="php"><![CDATA[
  62. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
  63. // /home/maarten/example.txt auf Azure hochladen
  64. $result = $storageClient->putBlob(
  65. 'testcontainer', 'example.txt', '/home/maarten/example.txt'
  66. );
  67. echo 'Der Name des Blobs ist: ' . $result->Name;
  68. ]]></programlisting>
  69. </example>
  70. </sect3>
  71. <sect3 id="zend.service.windowsazure.storage.blob.api.copy-blob">
  72. <title>Kopieren eines Blobs</title>
  73. <para>
  74. Bei Verwendung des folgenden Codes kann ein Blob von innerhalb des Speicher Accounts
  75. kopiert werden. Der Vorteil der Verwendung dieser Methode besteht darin das die
  76. Kopieroperation in der Azure Wolke stattfindet und kein Downloaden vom Blob
  77. stattfinden muss. Es ist zu beachten das in diesem Fall der Container bereits vorher
  78. erstellt worden sein muss.
  79. </para>
  80. <example id="zend.service.windowsazure.storage.blob.api.copy-blob">
  81. <title>Kopieren eines Blobs</title>
  82. <programlisting language="php"><![CDATA[
  83. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
  84. // Kopiert example.txt auf example2.txt
  85. $result = $storageClient->copyBlob(
  86. 'testcontainer', 'example.txt', 'testcontainer', 'example2.txt'
  87. );
  88. echo 'Der Name des kopierten Blobs ist: ' . $result->Name;
  89. ]]></programlisting>
  90. </example>
  91. </sect3>
  92. <sect3 id="zend.service.windowsazure.storage.blob.api.download-blob">
  93. <title>Herunterladen eines Blobs</title>
  94. <para>
  95. Bei Verwendung des folgenden Codes kann ein Blob von einem Blob Speicher Container
  96. auf den Development Speicher heruntergeladen werden. Es ist zu beachten das der
  97. Container hierfür bereits vorher erstellt wurden sein und ein Blob darauf
  98. hochgeladen sein muss.
  99. </para>
  100. <example id="zend.service.windowsazure.storage.blob.api.download-blob">
  101. <title>Herunterladen eines Blobs</title>
  102. <programlisting language="php"><![CDATA[
  103. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
  104. // Lädt die Datei /home/maarten/example.txt herunter
  105. $storageClient->getBlob(
  106. 'testcontainer', 'example.txt', '/home/maarten/example.txt'
  107. );
  108. ]]></programlisting>
  109. </example>
  110. </sect3>
  111. <sect3 id="zend.service.windowsazure.storage.blob.api.public-blob">
  112. <title>Einen Blob öffentlich verfügbar machen</title>
  113. <para>
  114. By default, blob storage containers on Windows Azure are protected from public
  115. viewing. If any user on the Internet should have access to a blob container, its ACL
  116. can be set to public. Note that this applies to a complete container and not to a
  117. single blob!
  118. </para>
  119. <para>
  120. Using the following code, blob storage container ACL can be set on development
  121. storage. Note that the container has already been created before.
  122. </para>
  123. <example id="zend.service.windowsazure.storage.blob.api.public-blob">
  124. <title>Making a blob publicly available</title>
  125. <programlisting language="php"><![CDATA[
  126. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
  127. // make container publicly available
  128. $storageClient->setContainerAcl('testcontainer', Zend_Service_WindowsAzure_Storage_Blob::ACL_PUBLIC);
  129. ]]></programlisting>
  130. </example>
  131. </sect3>
  132. </sect2>
  133. <sect2 id="zend.service.windowsazure.storage.blob.root">
  134. <title>Root container</title>
  135. <para>
  136. Windows Azure Blob Storage provides support to work with a "root container".
  137. This means that a blob can be stored in the root of your storage account,
  138. i.e. <code>http://myaccount.blob.core.windows.net/somefile.txt</code>.
  139. </para>
  140. <para>
  141. In order to work with the root container, it should first be created using the
  142. <methodname>createContainer()</methodname> method, naming the container
  143. <varname>$root</varname>. All other operations on the root container should be issued
  144. with the container name set to <varname>$root</varname>.
  145. </para>
  146. </sect2>
  147. <sect2 id="zend.service.windowsazure.storage.blob.wrapper">
  148. <title>Blob storage stream wrapper</title>
  149. <para>
  150. The Windows Azure SDK for PHP provides support for registering a blob storage
  151. client as a PHP file stream wrapper. The blob storage stream wrapper provides
  152. support for using regular file operations on Windows Azure Blob Storage.
  153. For example, one can open a file from Windows Azure Blob Storage with
  154. the <functionname>fopen()</functionname> function:
  155. </para>
  156. <example id="zend.service.windowsazure.storage.blob.wrapper.sample">
  157. <title>Example usage of blob storage stream wrapper</title>
  158. <programlisting language="php"><![CDATA[
  159. $fileHandle = fopen('azure://mycontainer/myfile.txt', 'r');
  160. // ...
  161. fclose($fileHandle);
  162. ]]></programlisting>
  163. </example>
  164. <para>
  165. In order to do this, the Windows Azure SDK for PHP blob storage client
  166. must be registered as a stream wrapper. This can be done by calling the
  167. <methodname>registerStreamWrapper()</methodname> method:
  168. </para>
  169. <example id="zend.service.windowsazure.storage.blob.wrapper.register">
  170. <title>Registering the blob storage stream wrapper</title>
  171. <programlisting language="php"><![CDATA[
  172. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
  173. $storageClient->registerStreamWrapper(); // registers azure:// on this storage client
  174. // or:
  175. $storageClient->registerStreamWrapper('blob://'); // regiters blob:// on this storage client
  176. ]]></programlisting>
  177. </example>
  178. <para>
  179. To unregister the stream wrapper, the <methodname>unregisterStreamWrapper()</methodname>
  180. method can be used.
  181. </para>
  182. </sect2>
  183. <sect2 id="zend.service.windowsazure.storage.blob.sharedaccesssig">
  184. <title>Shared Access Signature</title>
  185. <para>
  186. Windows Azure Bob Storage provides a feature called "Shared Access Signatures". By
  187. default, there is only one level of authorization possible in Windows Azure Blob
  188. Storage: either a container is private or it is public. Shared Access Signatures provide
  189. a more granular method of authorization: read, write, delete and list permissions can be
  190. assigned on a container or a blob and given to a specific client using an URL-based
  191. model.
  192. </para>
  193. <para>
  194. An example would be the following signature:
  195. </para>
  196. <literallayout>
  197. http://phpstorage.blob.core.windows.net/phpazuretestshared1?st=2009-08-17T09%3A06%3A17Z&amp;se=2009-08-17T09%3A56%3A17Z&amp;sr=c&amp;sp=w&amp;sig=hscQ7Su1nqd91OfMTwTkxabhJSaspx%2BD%2Fz8UqZAgn9s%3D
  198. </literallayout>
  199. <para>
  200. The above signature gives write access to the "phpazuretestshared1"
  201. container of the "phpstorage" account.
  202. </para>
  203. <sect3 id="zend.service.windowsazure.storage.blob.sharedaccesssig.generate">
  204. <title>Generating a Shared Access Signature</title>
  205. <para>
  206. When you are the owner of a Windows Azure Bob Storage account, you can create and
  207. distribute a shared access key for any type of resource in your account. To do this,
  208. the <methodname>generateSharedAccessUrl()</methodname> method of the
  209. <classname>Zend_Service_WindowsAzure_Storage_Blob</classname> storage client can be
  210. used.
  211. </para>
  212. <para>
  213. The following example code will generate a Shared Access Signature for write access
  214. in a container named "container1", within a timeframe of 3000 seconds.
  215. </para>
  216. <example id="zend.service.windowsazure.storage.blob.sharedaccesssig.generate-2">
  217. <title>Generating a Shared Access Signature for a container</title>
  218. <programlisting language="php"><![CDATA[
  219. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
  220. $sharedAccessUrl = storageClient->generateSharedAccessUrl(
  221. 'container1',
  222. '',
  223. 'c',
  224. 'w',
  225. $storageClient ->isoDate(time() - 500),
  226. $storageClient ->isoDate(time() + 3000)
  227. );
  228. ]]></programlisting>
  229. </example>
  230. <para>
  231. The following example code will generate a Shared Access Signature for read access
  232. in a blob named <filename>test.txt</filename> in a container named "container1"
  233. within a time frame of 3000 seconds.
  234. </para>
  235. <example id="zend.service.windowsazure.storage.blob.sharedaccesssig-generate-3">
  236. <title>Generating a Shared Access Signature for a blob</title>
  237. <programlisting language="php"><![CDATA[
  238. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
  239. $sharedAccessUrl = storageClient->generateSharedAccessUrl(
  240. 'container1',
  241. 'test.txt',
  242. 'b',
  243. 'r',
  244. $storageClient ->isoDate(time() - 500),
  245. $storageClient ->isoDate(time() + 3000)
  246. );
  247. ]]></programlisting>
  248. </example>
  249. </sect3>
  250. <sect3 id="zend.service.windowsazure.storage.blob.sharedaccesssig.consume">
  251. <title>Working with Shared Access Signatures from others</title>
  252. <para>
  253. When you receive a Shared Access Signature from someone else, you can use the
  254. Windows Azure SDK for PHP to work with the addressed resource. For example, the
  255. following signature can be retrieved from the owner of a storage account:
  256. </para>
  257. <literallayout>
  258. http://phpstorage.blob.core.windows.net/phpazuretestshared1?st=2009-08-17T09%3A06%3A17Z&amp;se=2009-08-17T09%3A56%3A17Z&amp;sr=c&amp;sp=w&amp;sig=hscQ7Su1nqd91OfMTwTkxabhJSaspx%2BD%2Fz8UqZAgn9s%3D
  259. </literallayout>
  260. <para>
  261. The above signature gives write access to the "phpazuretestshared1" "container" of
  262. the phpstorage account. Since the shared key for the account is not known, the
  263. Shared Access Signature can be used to work with the authorized resource.
  264. </para>
  265. <example id="zend.service.windowsazure.storage.blob.sharedaccesssig.consuming">
  266. <title>Consuming a Shared Access Signature for a container</title>
  267. <programlisting language="php"><![CDATA[
  268. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob(
  269. 'blob.core.windows.net', 'phpstorage', ''
  270. );
  271. $storageClient->setCredentials(
  272. new Zend_Service_WindowsAzure_Credentials_SharedAccessSignature()
  273. );
  274. $storageClient->getCredentials()->setPermissionSet(array(
  275. 'http://phpstorage.blob.core.windows.net/phpazuretestshared1?st=2009-08-17T09%3A06%3A17Z&se=2009-08-17T09%3A56%3A17Z&sr=c&sp=w&sig=hscQ7Su1nqd91OfMTwTkxabhJSaspx%2BD%2Fz8UqZAgn9s%3D'
  276. ));
  277. $storageClient->putBlob(
  278. 'phpazuretestshared1', 'NewBlob.txt', 'C:\Files\dataforazure.txt'
  279. );
  280. ]]></programlisting>
  281. </example>
  282. <para>
  283. Note that there was no explicit permission to write to a specific blob. Instead, the
  284. Windows Azure SDK for PHP determined that a permission was required to either write
  285. to that specific blob, or to write to its container. Since only a signature was
  286. available for the latter, the Windows Azure SDK for PHP chose those credentials to
  287. perform the request on Windows Azure blob storage.
  288. </para>
  289. </sect3>
  290. </sect2>
  291. </sect1>