Successfully Saving base64 Image to Azure Blob storage but blob image always broken/small white box

前端 未结 1 1645
迷失自我
迷失自我 2021-02-06 19:02

I have a image converted to base64 I am trying to upload to my azure blob storage using createBlockBlobFromText.

self.blobServer.createBlockBlobFromText(containe         


        
相关标签:
1条回答
  • 2021-02-06 19:34

    To visit the images directly via Urls in browser requires binary content. You can convert the base64 encoded string to binary buffer in your node.js backend, and upload the buffer string to Azure Storage.

    Please try the following code snippet:

    var rawdata = 'data:image/jpeg;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==';
    var matches = rawdata.match(/^data:([A-Za-z-+\/]+);base64,(.+)$/);
    var type = matches[1];
    var buffer = new Buffer(matches[2], 'base64');
    
    blobsrv.createBlockBlobFromText('mycontainer','profile-pic-123.jpg', buffer, {contentType:type}, function(error, result, response) {
            if (error) {
                console.log(error);
            }else{
             console.log(result)
            }
        });
    
    0 讨论(0)
提交回复
热议问题