我是Azure & node.js初学者。我试图在node.js上执行文件上传示例,但它不起作用,在blob.client.createContainerIfNotExists()
。node.js azure存储blob
错误显示:
Error: createContainerIfNotExists
这意味着createContainerIfNotExists()
显示简单的该错误情况。
不知我是否错误怎么写blob.client.createContainerIfNotExists()
或者azure.createBlobService()
不能成功。
node.js version v0.6.12
express version 2.5.11
azure version 0.5.3
谢谢!
/**********************/
File upload sample:
/**********************/
var DEVSTORE_STORAGE_ACCOUNT = 'xxxxx';
var DEVSTORE_STORAGE_ACCESS_KEY= 'xxxx';
var DEVSTORE_BLOB_HOST = 'xxxxx';
var express = require('express')
, routes = require('./routes');
var util = require('util');
// Azure module
var azure = require('azure');
var blob = require('./blob.js');
// BLOB container
blob.CONTAINER = 'nodejs';
// BLOB service
blob.client = azure.createBlobService(
DEVSTORE_STORAGE_ACCOUNT,
DEVSTORE_STORAGE_ACCESS_KEY,
DEVSTORE_BLOB_HOST);
var app = module.exports = express.createServer();
// Configuration
app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.bodyParser());
app.use(express.methodOverride());
// app.use(express.logger());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.use(express.errorHandler());
});
// Routes
app.get('/', routes.index);
// BLOB upload
app.get('/upload', routes.upload);
// BLOB upload
app.post('/uploadtoblob', routes.uploadblob);
// BLOB list
app.get('/list', routes.listblobs);
// BLOB delete
app.post('/delete/:id', routes.deleteblob);
// BLOB property
app.get('/info/:id', routes.information);
// BLOB container create
blob.client.createContainerIfNotExists(blob.CONTAINER, function(err) {
if (err) {
console.log('Error : createContainerIfNotExists');
process.exit(1);
} else {
blob.client.setContainerAcl(blob.CONTAINER, azure.Constants.BlobConstants.BlobContainerPublicAccessType.BLOB, function(err) {
if(err) {
console.log('Error : setContainerAcl');
process.exit(1);
}
});
}
});
var port = process.env.port || 3000;
app.listen(port, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});
这可能是值得的追踪器通过诸如Fiddler工具的请求/响应或记录的细节实际错误。那会准确地告诉你为什么你的请求失败。它可能会因任何原因失败 - 无效的BLOB容器名称,无效的凭据等。 –
谢谢您的评论!我会尝试。 – otogen
你也可以在console.log中打印更多的数据(例如,输出你得到的实际错误)。这可能仅仅是错误的证书,但是如果没有更多的信息,就不可能进行调试。 –