成功将base64映像保存到Azure Blob存储,但Blob映像始终损坏/白色小框 [英] Successfully Saving base64 Image to Azure Blob storage but blob image always broken/small white box

查看:143
本文介绍了成功将base64映像保存到Azure Blob存储,但Blob映像始终损坏/白色小框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图像转换为base64,我试图使用createBlockBlobFromText上传到我的Azure Blob存储.

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

self.blobServer.createBlockBlobFromText(containerName, fileName, baseStrChars, { contentSettings: { contentType: 'image/jpeg' } }, function(error, result, response) {
     if (error) {
         console.log(error);
     }
     console.log("result", result);
     console.log("response", response);
});

我的新jpeg图像出现在blob存储容器中,但是当我转到blob图像URL时,我总是得到.

My new jpeg image appears in blob storage container but when I go to the blob image URL I always get this.

我的容器的访问策略设置为container,我将我的base64字符串粘贴到了base64到图像转换器,然后出现了正确的图像.问题似乎是我创建blob而不是base64字符串的方式.

My container's access policy is set to container and I pasted my base64 string to a base64 to image converter and the correct image appears. The problem seems to be the way I create the blob and not the base64 string.

我对为什么整个流程似乎都正常工作感到困惑,但是当我转到URL时,图像仍然坏了.有什么想法吗?

I am puzzled as to why the whole flow seems to be working, but still the image is broken when I go to the URL. Any ideas ?

推荐答案

在浏览器中直接通过Urls访问图像需要二进制内容.您可以将base64编码的字符串转换为node.js后端中的二进制缓冲区,然后将该缓冲区字符串上传到Azure存储.

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.

请尝试以下代码段:

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)
        }
    });

这篇关于成功将base64映像保存到Azure Blob存储,但Blob映像始终损坏/白色小框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆