I'm following http://willi.am/blog/2014/07/03/azure-blob-storage-and-node-downloading-blobs/.
However despite the exact same code, when I download blobs Azure gives the error:
[Error: Hash mismatch (integrity check failed), Expected value is ...]
The line being run is blobService.getBlobToText, with blobService being the connection to Azure (createBlobService...)
What's going on? :S
My code's below:
// 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();