Reputation: 31
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();
Upvotes: 3
Views: 4360
Reputation: 11
When you store a Buffer object, you can retrieve it with getBlobToStream.
const data: Buffer[] = [];
const stream = new PassThrough();
stream.on('data', (d: Buffer) => {
data.push(d);
});
this.blobStorageContext.service.getBlobToStream(
this.blobStorageContext.getContainerName(),
blobName, stream, (error) => {
if (error) {
console.log(error);
} else {
console.log(Buffer.concat(data));
}
});
Upvotes: 1
Reputation: 511
In case someone else runs into this; happens when you store a Buffer
object but retrieve a string
.
Upvotes: 6
Reputation: 2282
I've recently ran into this problem myself. Somehow npm -install azure-storage -g helped it. It might be that the package is updated on the npm and md5 calculation has changed since. Once I updated the azure-storage package, everything works like a charm.
Upvotes: 0
Reputation: 136356
Try something like the following (modifying the code from the blog post you mentioned):
var blobName = 'my-awesome-text-blob';
blobService.getBlobToText(
containerName,
blobName, {'disableContentMD5Validation': true },
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);
}
});
See if this helps.
Upvotes: 2
Reputation: 572
It can happen because of many internal MD5 check failures which works differently when you use HTTPS. Can you please try specifying your storage account as https? Like -
var blobService = storage.createBlobServiceAnonymous('https://MyAccountXX.blob.core.windows.net/');
Otherwise for me, this download function is working fine.
For reference, you can try following actual documentation - https://azure.microsoft.com/en-in/documentation/articles/storage-nodejs-how-to-use-blob-storage/
Upvotes: 1