node.js azure存储blob
我是Azure&node.js初学者。我试图在node.js上执行下面的文件上载示例,但在node.js azure存储blob,node.js,azure,azure-storage-blobs,Node.js,Azure,Azure Storage Blobs,我是Azure&node.js初学者。我试图在node.js上执行下面的文件上载示例,但在blob.client.createContainerIfNotExists()上它不起作用 错误显示: Error: createContainerIfNotExists 这意味着createContainerIfNotExists()的错误情况只会简单地显示出来 我想知道我是否错误地编写了blob.client.createContainerIfNotExists(),或者,azure.createB
blob.client.createContainerIfNotExists()
上它不起作用
错误显示:
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);
});
最新的azure sdk for node要求节点版本>0.6.l5。我建议升级sdk和节点版本 您可以按如下方式更改代码,以获取有关特定错误的更多信息: log('Error:createContainerIfNotExists'+JSON.stringify(err)) 您需要让azure storage emulator在本地运行,或者需要为应用程序可以使用的azure存储帐户提供凭据。通常通过AZURE_STORAGE_帐户和AZURE_STORAGE_ACCESS_密钥环境变量,或者通过向createBlobService工厂传递连接字符串来完成 有关使用blob存储设置第一个应用程序的分步示例,请参阅:
通过Fiddler之类的工具跟踪请求/响应或记录实际错误的详细信息可能是值得的。这将确切地告诉您请求失败的原因。它可能会因多种原因而失败-无效的blob容器名称、无效的凭据等。感谢您的评论!我会试试。你也可以尝试在console.log中打印更多数据(例如,输出你得到的实际错误)。这可能只是错误的凭据,但如果没有有关错误的更多信息,则无法进行调试。谢谢您的评论。谢谢您的回答。我认为这个问题已经完全过时了。