Zend_Service_WindowsAzure_Blob.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.service.windowsazure.storage.blob">
  4. <title>Zend_Service_WindowsAzure_Storage_Blob</title>
  5. <para>
  6. Blob Storage stores sets of binary data. Blob storage offers the following three
  7. resources: the storage account, containers, and blobs. Within your storage account,
  8. containers provide a way to organize sets of blobs within your storage account.
  9. </para>
  10. <para>
  11. Blob Storage is offered by Windows Azure as a <acronym>REST</acronym> <acronym>API</acronym>
  12. which is wrapped by the <classname>Zend_Service_WindowsAzure_Storage_Blob</classname> class
  13. in order to provide a native <acronym>PHP</acronym> interface to the storage account.
  14. </para>
  15. <sect2 id="zend.service.windowsazure.storage.blob.api">
  16. <title>API Examples</title>
  17. <para>
  18. This topic lists some examples of using the
  19. <classname>Zend_Service_WindowsAzure_Storage_Blob</classname> class. Other features are
  20. available in the download package, as well as a detailed <acronym>API</acronym>
  21. documentation of those features.
  22. </para>
  23. <sect3 id="zend.service.windowsazure.storage.blob.api.create-container">
  24. <title>Creating a storage container</title>
  25. <para>
  26. Using the following code, a blob storage container can be created on development
  27. storage.
  28. </para>
  29. <example id="zend.service.windowsazure.storage.blob.api.create-container.example">
  30. <title>Creating a storage container</title>
  31. <programlisting language="php"><![CDATA[
  32. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
  33. $result = $storageClient->createContainer('testcontainer');
  34. echo 'Container name is: ' . $result->Name;
  35. ]]></programlisting>
  36. </example>
  37. </sect3>
  38. <sect3 id="zend.service.windowsazure.storage.blob.api.delete-container">
  39. <title>Deleting a storage container</title>
  40. <para>
  41. Using the following code, a blob storage container can be removed from development
  42. storage.
  43. </para>
  44. <example id="zend.service.windowsazure.storage.blob.api.delete-container.example">
  45. <title>Deleting a storage container</title>
  46. <programlisting language="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>Storing a blob</title>
  54. <para>
  55. Using the following code, a blob can be uploaded to a blob storage container on
  56. development storage. Note that the container has already been created before.
  57. </para>
  58. <example id="zend.service.windowsazure.storage.blob.api.storing-blob.example">
  59. <title>Storing a blob</title>
  60. <programlisting language="php"><![CDATA[
  61. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
  62. // upload /home/maarten/example.txt to Azure
  63. $result = $storageClient->putBlob(
  64. 'testcontainer', 'example.txt', '/home/maarten/example.txt'
  65. );
  66. echo 'Blob name is: ' . $result->Name;
  67. ]]></programlisting>
  68. </example>
  69. </sect3>
  70. <sect3 id="zend.service.windowsazure.storage.blob.api.copy-blob">
  71. <title>Copying a blob</title>
  72. <para>
  73. Using the following code, a blob can be copied from inside the storage account. The
  74. advantage of using this method is that the copy operation occurs in the Azure cloud
  75. and does not involve downloading the blob. Note that the container has already been
  76. created before.
  77. </para>
  78. <example id="zend.service.windowsazure.storage.blob.api.copy-blob.example">
  79. <title>Copying a blob</title>
  80. <programlisting language="php"><![CDATA[
  81. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
  82. // copy example.txt to example2.txt
  83. $result = $storageClient->copyBlob(
  84. 'testcontainer', 'example.txt', 'testcontainer', 'example2.txt'
  85. );
  86. echo 'Copied blob name is: ' . $result->Name;
  87. ]]></programlisting>
  88. </example>
  89. </sect3>
  90. <sect3 id="zend.service.windowsazure.storage.blob.api.download-blob">
  91. <title>Downloading a blob</title>
  92. <para>
  93. Using the following code, a blob can be downloaded from a blob storage container on
  94. development storage. Note that the container has already been created before and a
  95. blob has been uploaded.
  96. </para>
  97. <example id="zend.service.windowsazure.storage.blob.api.download-blob.example">
  98. <title>Downloading a blob</title>
  99. <programlisting language="php"><![CDATA[
  100. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
  101. // download file to /home/maarten/example.txt
  102. $storageClient->getBlob(
  103. 'testcontainer', 'example.txt', '/home/maarten/example.txt'
  104. );
  105. ]]></programlisting>
  106. </example>
  107. </sect3>
  108. <sect3 id="zend.service.windowsazure.storage.blob.api.public-blob">
  109. <title>Making a blob publicly available</title>
  110. <para>
  111. By default, blob storage containers on Windows Azure are protected from public
  112. viewing. If any user on the Internet should have access to a blob container, its ACL
  113. can be set to public. Note that this applies to a complete container and not to a
  114. single blob!
  115. </para>
  116. <para>
  117. Using the following code, blob storage container ACL can be set on development
  118. storage. Note that the container has already been created before.
  119. </para>
  120. <example id="zend.service.windowsazure.storage.blob.api.public-blob.example">
  121. <title>Making a blob publicly available</title>
  122. <programlisting language="php"><![CDATA[
  123. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
  124. // make container publicly available (enumerate all blobs and read blob data)
  125. $storageClient->setContainerAcl('testcontainer', Zend_Service_WindowsAzure_Storage_Blob::ACL_PUBLIC_CONTAINER);
  126. ]]></programlisting>
  127. </example>
  128. </sect3>
  129. </sect2>
  130. <sect2 id="zend.service.windowsazure.storage.blob.root">
  131. <title>Root container</title>
  132. <para>
  133. Windows Azure Blob Storage provides support to work with a "root container".
  134. This means that a blob can be stored in the root of your storage account,
  135. i.e. <filename>http://myaccount.blob.core.windows.net/somefile.txt</filename>.
  136. </para>
  137. <para>
  138. In order to work with the root container, it should first be created using the
  139. <methodname>createContainer()</methodname> method, naming the container
  140. <varname>$root</varname>. All other operations on the root container should be issued
  141. with the container name set to <varname>$root</varname>.
  142. </para>
  143. </sect2>
  144. <sect2 id="zend.service.windowsazure.storage.blob.wrapper">
  145. <title>Blob storage stream wrapper</title>
  146. <para>
  147. The Windows Azure <acronym>SDK</acronym> for <acronym>PHP</acronym> provides support
  148. for registering a blob storage client as a <acronym>PHP</acronym> file stream wrapper.
  149. The blob storage stream wrapper provides support for using regular file operations on
  150. Windows Azure Blob Storage. For example, one can open a file from Windows Azure Blob
  151. Storage with the <methodname>fopen()</methodname> function:
  152. </para>
  153. <example id="zend.service.windowsazure.storage.blob.wrapper.sample">
  154. <title>Example usage of blob storage stream wrapper</title>
  155. <programlisting language="php"><![CDATA[
  156. $fileHandle = fopen('azure://mycontainer/myfile.txt', 'r');
  157. // ...
  158. fclose($fileHandle);
  159. ]]></programlisting>
  160. </example>
  161. <para>
  162. In order to do this, the Windows Azure <acronym>SDK</acronym> for <acronym>PHP</acronym>
  163. blob storage client must be registered as a stream wrapper. This can be done by calling
  164. the <methodname>registerStreamWrapper()</methodname> method:
  165. </para>
  166. <example id="zend.service.windowsazure.storage.blob.wrapper.register">
  167. <title>Registering the blob storage stream wrapper</title>
  168. <programlisting language="php"><![CDATA[
  169. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
  170. // registers azure:// on this storage client
  171. $storageClient->registerStreamWrapper();
  172. // or:
  173. // regiters blob:// on this storage client
  174. $storageClient->registerStreamWrapper('blob://');
  175. ]]></programlisting>
  176. </example>
  177. <para>
  178. To unregister the stream wrapper, the <methodname>unregisterStreamWrapper()</methodname>
  179. method can be used.
  180. </para>
  181. </sect2>
  182. <sect2 id="zend.service.windowsazure.storage.blob.sharedaccesssig">
  183. <title>Shared Access Signature</title>
  184. <para>
  185. Windows Azure Bob Storage provides a feature called "Shared Access Signatures". By
  186. default, there is only one level of authorization possible in Windows Azure Blob
  187. Storage: either a container is private or it is public. Shared Access Signatures provide
  188. a more granular method of authorization: read, write, delete and list permissions can be
  189. assigned on a container or a blob and given to a specific client using an URL-based
  190. model.
  191. </para>
  192. <para>
  193. An example would be the following signature:
  194. </para>
  195. <literallayout>
  196. 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
  197. </literallayout>
  198. <para>
  199. The above signature gives write access to the "phpazuretestshared1"
  200. container of the "phpstorage" account.
  201. </para>
  202. <sect3 id="zend.service.windowsazure.storage.blob.sharedaccesssig.generate">
  203. <title>Generating a Shared Access Signature</title>
  204. <para>
  205. When you are the owner of a Windows Azure Bob Storage account, you can create and
  206. distribute a shared access key for any type of resource in your account. To do this,
  207. the <methodname>generateSharedAccessUrl()</methodname> method of the
  208. <classname>Zend_Service_WindowsAzure_Storage_Blob</classname> storage client can be
  209. used.
  210. </para>
  211. <para>
  212. The following example code will generate a Shared Access Signature for write access
  213. in a container named "container1", within a timeframe of 3000 seconds.
  214. </para>
  215. <example id="zend.service.windowsazure.storage.blob.sharedaccesssig.generate-2">
  216. <title>Generating a Shared Access Signature for a container</title>
  217. <programlisting language="php"><![CDATA[
  218. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
  219. $sharedAccessUrl = $storageClient->generateSharedAccessUrl(
  220. 'container1',
  221. '',
  222. 'c',
  223. 'w',
  224. $storageClient ->isoDate(time() - 500),
  225. $storageClient ->isoDate(time() + 3000)
  226. );
  227. ]]></programlisting>
  228. </example>
  229. <para>
  230. The following example code will generate a Shared Access Signature for read access
  231. in a blob named <filename>test.txt</filename> in a container named "container1"
  232. within a time frame of 3000 seconds.
  233. </para>
  234. <example id="zend.service.windowsazure.storage.blob.sharedaccesssig-generate-3">
  235. <title>Generating a Shared Access Signature for a blob</title>
  236. <programlisting language="php"><![CDATA[
  237. $storageClient = new Zend_Service_WindowsAzure_Storage_Blob();
  238. $sharedAccessUrl = $storageClient->generateSharedAccessUrl(
  239. 'container1',
  240. 'test.txt',
  241. 'b',
  242. 'r',
  243. $storageClient ->isoDate(time() - 500),
  244. $storageClient ->isoDate(time() + 3000)
  245. );
  246. ]]></programlisting>
  247. </example>
  248. </sect3>
  249. <sect3 id="zend.service.windowsazure.storage.blob.sharedaccesssig.consume">
  250. <title>Working with Shared Access Signatures from others</title>
  251. <para>
  252. When you receive a Shared Access Signature from someone else, you can use the
  253. Windows Azure <acronym>SDK</acronym> for <acronym>PHP</acronym> to work with the
  254. addressed resource. For example, the following signature can be retrieved from the
  255. 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 <acronym>SDK</acronym> for <acronym>PHP</acronym> determined that a
  285. permission was required to either write to that specific blob, or to write to its
  286. container. Since only a signature was available for the latter, the Windows Azure
  287. <acronym>SDK</acronym> for <acronym>PHP</acronym> chose those credentials to perform
  288. the request on Windows Azure blob storage.
  289. </para>
  290. </sect3>
  291. </sect2>
  292. </sect1>