您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

用于 Node.js 的 Azure 存储模块Azure Storage modules for Node.js

使用 Azure 存储客户端模块可以:Use the Azure Storage client module to:

使用管理模块通过 Node.js 应用创建、更新和管理 Azure 存储帐户,以及查询和重新生成访问密钥。Create, update, and manage Azure Storage accounts and query and regenerate access keys from your Node.js apps with the management modules.

客户端包Client Package

安装 npm 模块Install the npm module

安装 Azure 存储客户端 npm 模块Install the Azure storage client npm module

npm install azure-storage

示例Example

此示例创建一个存储容器,并将本地文件 data.txt 上传到其中。This example create a storage container and uploads a local file data.txt to it.

const azure = require('azure-storage');
const blobService = azure.createBlobService(storageConnectionString);

const container = 'taskcontainer';
const task = 'taskblob';
const filename = 'data.txt';

blobService.createContainerIfNotExists(container, error => {
  if (error) return console.log(error);
  blobService.createBlockBlobFromLocalFile(
    container,
    task,
    filename,
    (error, result) => {
      if (error) return console.log(error);
      console.dir(result, { depth: null, colors: true });
    }
  );
});

管理包Management Package

安装 npm 模块Install the npm module

安装 Azure 存储管理 npm 模块Install the Azure storage management npm module

npm install azure-arm-storage

示例Example

此示例列出存储帐户。This example list the storage accounts.

const msRestAzure = require('ms-rest-azure');
const storageManagementClient = require('azure-arm-storage');

const subscriptionId = 'your-subscription-id';

msRestAzure
  .interactiveLogin()
  .then(credentials => {
    const client = new storageManagementClient(
      credentials,
      subscriptionId
    );
    return client.storageAccounts.list();
  })
  .then(accounts => console.dir(accounts, { depth: null, colors: true }))
  .catch(err => console.log(err));

示例Samples

详细了解可在应用中使用的示例 Node.js 代码Explore more sample Node.js code you can use in your apps.