0
votes

Based on this post, this should be possible. However, I can't make it work. One confusing part is that am I using the correct version of azure-storage? In that post, timm said one year ago

This is released in 0.9.x.

However, there is no version of 0.9. The latest of azure-storage is 0.6.0.

Here is my server code (node.js):

var buf = new Buffer(upd.picture, 'binary');
blobService.createBlockBlobFromText(containerName, fileName, buf, function (error, result, response) {
});

On client side (angular.js), the binary data is read like this:

var file = document.getElementById('file').files[0];
var reader = new FileReader();
reader.onloadend = function (e) {
    upd.picture = e.target.result;
    ....
}
reader.readAsBinaryString(file);

For my testing, I uploaded a jpg image, the file saved in azure blob can't be displayed in web browser. However, if I use createBlockBlobFromLocalFile to upload the file, it works. What did I do wrong?

UPDATE:

Okay, I finally figured it out. I just need to change one line above to

var buf = new Buffer(upd.picture.substr(23), 'base64');

The problem was that the file is already converted to based64 with header "data:image/jpeg;base64," which messed up the binary data.

1
May be you'd need to provide the Content-Type header saying it's an image. Have a look at that post : stackoverflow.com/questions/15450102/…Emmanuel DURIN
I wondered that too, but what do I suppose to put as content-type?newman
I tried to add options = { contentType: 'image/jpeg' , contentTypeHeader: 'image/jpeg' }, but it didn't help.newman

1 Answers

0
votes

To clarify the version issue, the version timm mentioned is the version of "azure" module. Now the Azure Storage SDK is released with "azure-storage" module. Using the latest module might resolve your issue.