有多種方式可以提供您的存儲訪問憑據。我正在使用環境變量來設置帳戶名稱和密鑰。
這是我如何使用bash設置環境變量:
echo Exporting Azure Storage variables ...
export AZURE_STORAGE_ACCOUNT='YOUR_ACCOUNT_NAME'
export AZURE_STORAGE_ACCESS_KEY='YOUR_ACCESS_KEY'
echo Done exporting Azure Storage variables
這裏是一個樣本的node.js腳本,我用它來生成存儲爲Azure的斑點現有圖像的縮略圖,使用ImageMagick:
var azure = require('azure');
var im = require('imagemagick');
var fs = require('fs');
var rt = require('runtimer');
//Blobservice init
var blobService = azure.createBlobService();
var convertPath = '/usr/bin/convert';
var identifyPath = '/usr/bin/identify';
global.once = false;
var blobs = blobService.listBlobs("screenshots", function (error, blobs) {
if (error) {
console.log(error);
}
if (!error) {
blobs.forEach(function (item) {
if (item.name) {
if (item.name.length == 59) {
//Create the name for the thum
var thumb = item.name.substring(0, item.name.indexOf('_')) + '_thumb.png';
if (!global.once) {
console.log(global.once);
var info = blobService.getBlobToFile("YOUR CONTAINER", item.name, item.name,
function (error, blockBlob, response) {
im.resize({
srcPath: item.name,
dstPath: thumb,
width: 100,
height: 200
},
function (err, sdout, stderr) {
if (err) throw err;
console.log("resized");
//Delete the downloaded BIG one
fs.unlinkSync(item.name);
//Upload the thumbnail
blobService.putBlockBlobFromFile("YOUR CONTAINER", thumb, thumb,
function (error, blockBlob, response) {
if (!error) {
console.log("blob uploaded: " + thumb);
fs.unlinkSync(thumb);
}
});
});
});
//DEBUG: Uncomment to test only with one file
//global.once = true;
}
}
}
});
}
});
這裏是爲節點在Azure模塊的官方鏈接(它包含了一些樣品):
Windows Azure Client Library for node
太棒了!感謝您的即時回覆! – balanv