我正在参照http://willi.am/blog/2014/07/03/azure-blob-storage-and-node-downloading-blobs/的示例。但是,尽管使用了完全相同的代码,当我下载blob时,Azure会报错:
[Error: Hash mismatch (integrity check failed), Expected value is ...]
运行的行是 blobService.getBlobToText,blobService是连接Azure的对象(createBlobService...)。这是怎么回事? :S
以下是我的代码:
[Error: Hash mismatch (integrity check failed), Expected value is ...]
运行的行是 blobService.getBlobToText,blobService是连接Azure的对象(createBlobService...)。这是怎么回事? :S
以下是我的代码:
// Azure test
function downloadImageAsText(blobService, containerName, blobName) {
blobService.getBlobToText(
containerName,
blobName,
function(err, blobContent, blob) {
if (err) {
console.error("Couldn't download blob %s", blobName);
console.error(err);
} else {
console.log("Sucessfully downloaded blob %s", blobName);
console.log(blobContent);
}
});
}
function uploadImage(blobService, containerName, blobName, fileName) {
blobService.getBlobProperties(
containerName,
blobName,
function(err, properties, status) {
if (status.isSuccessful) {
// Blob exists
} else {
blobService.createBlockBlobFromLocalFile(
containerName,
blobName,
fileName,
function(error, result, response){
if(error){
console.log("Couldn't upload file %s", fileName);
console.error(error);
} else {
console.log('File %s uploaded successfully', fileName);
downloadImageAsText(blobService, containerName, blobName);
}
});
}
});
}
function testAzure() {
accountName / hash = my details
var storage = require('azure-storage');
var blobService = storage.createBlobService(accountName, hash);
var containerName = 'tst';
var blobName = 'test.png';
var fileName = 'test.png';
blobService.createContainerIfNotExists(containerName, function(err, result, response) {
if (err) {
console.log("Couldn't create container %s", containerName);
console.error(err);
} else {
if (result) {
console.log('Container %s created', containerName);
uploadImage(blobService, containerName, blobName, fileName);
} else {
console.log('Container %s already exists', containerName);
uploadImage(blobService, containerName, blobName, fileName);
}
}
});
}
function startServer() {
http = require('http');
const PORT = 8080;
var server = http.createServer(handleRequest);
server.on('listening',function(){
console.log("Server listening on: http://178.62.117.207:%s", PORT);
});
server.listen(PORT);
}
startServer();
testAzure();
Buffer
存储在 blob 中,但是却使用getBlobToText
将该数据作为String
检索出来。由于两种类型之间哈希计算的原因不同,所以操作失败了。 - lionello