Sie sind auf Seite 1von 2

Configure Your Application to Access Storage

To use Windows Azure storage, you need to download and use the Node.js azure package, which includes a set of convenience libraries that communicate with the storage REST services. Use Node Package Manager (NPM) to obtain the package 1.Use a command-line interface such as PowerShell (Windows,) Terminal (Mac,) or Bash (Unix), navigate to the folder where you created your sample application. 2.Type npm install azure in the command window, which should result in the following output: azure@0.6.0 ./node_modules/azure easy-table@0.0.1 dateformat@1.0.2-1.2.3 xmlbuilder@0.3.1 eyes@0.1.7 colors@0.6.0-1 mime@1.2.5 log@1.3.0 commander@0.6.1 node-uuid@1.2.0 xml2js@0.1.14 async@0.1.22 tunnel@0.0.1 underscore@1.3.3 qs@0.5.0 underscore.string@2.2.0rc sax@0.4.0 streamline@0.2.4 winston@0.6.1 (cycle@1.0.0, stack-trace@0.0.6, pkginfo@0.2.3, request@2.9.202) 3.You can manually run the ls command to verify that a node_modules folder was created. Inside that folder find the azure package, which contains the libraries you need to access storage. Import the package Using Notepad or another text editor, add the following to the top the server.js file of the application where you intend to use storage: var azure = require('azure');

Setup a Windows Azure Storage Connection

The azure module will read the environment variables AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_ACCESS_KEY for information required to connect to your Windows Azure storage account. If these environment variables are not set, you must specify the account information when callingcreateBlobService. For an example of setting the environment variables in a configuration file for a Windows Azure Cloud Service, see Node.js Cloud Service with Storage. For an example of setting the environment variables in the management portal for a Windows Azure Web Site, see Node.js Web Application with Storage

How to: Create a Container

The BlobService object lets you work with containers and blobs. The following code creates a BlobServiceobject. Add the following near the top of server.js: var blobService = azure.createBlobService(); All blobs reside in a container. The call to createContainerIfNotExists on the BlobService object will return the specified container if it exists or create a new container with the specified name if it does not already exist. By default, the new container is private and requires the use of the access key to download blobs from this container. blobService.createContainerIfNotExists(containerName, function(error){ if(!error){ // Container exists and is private } }); If you want to make the files in the container public so that they can be accessed without requiring the access key, you can set the containers access level to blob or container. Setting the access level to bloballows anonymous read access to blob content and metadata within this container, but not to container metadata such as listing all blobs within a container. Setting the access level to container allows anonymous read access to blob content and metadata as well as container metadata. The following example demonstrates setting the access level to blob: blobService.createContainerIfNotExists(containerName , {publicAccessLevel : 'blob'} , function(error){ if(!error){ // Container exists and is public } }); Alternatively, you can modify the access level of a container by using setContainerAcl to specify the access level.

Das könnte Ihnen auch gefallen