我正在为我的应用程序使用compoundjs,现在我试图实现一个脚本,该脚本可以从CompoundJS将图像上传到azure blob。
我搜索了web,发现有一个模块azure (npm )是在此链接中指定的。
下面是我在应用程序中使用的代码片段
var azure = require("azure");
var blobService = azure.createBlobService();
blobService.createContainerIfNotExists('container_name', {publicAccessLevel : 'blob'}, function(error){
if(!error){
// Container exists and is public
console.log("Container Exists");
}
});我知道我应该在哪里配置ACCESS KEY以使其工作,但不确定在哪里工作。
请建议一下。
发布于 2014-01-20 06:57:33
您需要提供如下所示的帐户名称/密钥:
var blobService = azure.createBlobService('accountname', 'accountkey');您可以在这里查看源代码:https://github.com/WindowsAzure/azure-sdk-for-node/blob/master/lib/azure.js。
发布于 2014-01-20 16:38:25
提供存储访问凭据的方法有多种。我使用环境变量来设置帐户名和密钥。
下面是如何使用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;
}
}
}
});
}
});以下是Node Azure模块的官方链接(它包含一些示例):
https://stackoverflow.com/questions/21227584
复制相似问题