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.