weixin_33725722 2016-05-15 10:26 采纳率: 0%
浏览 1065

使用Blob作为src映像

I'm storing images as blob in my MySQL BDD.
I call my node API that return me my BDD lines with JQuery Ajax :

$.ajax({
    url: "http://mydinners.fr:5280/partner",
    type: "GET",
    datatype: "json",
    contentType: "application/json; charset=utf-8",
    success: function(text){
        for(var i=0; i<text["message"].length; i++){
            var objurl = window.URL.createObjectURL(new Blob(text["message"][i]["partner_image"]));

            // text["message"][i]["image"] is an array of point like : [192,257,54,269,85,458,...]

            var module = "";
            module += "<img class='activator' src='"+objurl+"'>";

            $(".container .row").append(module);
        }
    }
});

The objurl value is something like this : "blob:http%3A//dev.mydinners.fr/e73c5c6f-562e-4b66-9d4e-7a4c8567532e"

But the image is like this : http://i.stack.imgur.com/Vhma7.png

Do you know how to translate my blob image from mysql to img ? thx.

  • 写回答

1条回答 默认 最新

  • weixin_33720452 2016-05-15 10:46
    关注

    You have to convert the array to a binary data (using Uint8Array) before creating the blob

    var binary = new Uint8Array(json.message[0].partner_image)

    This is somewhat irrelevant, but it's a working example when you use Uint8Array, I just choose my own way of fetching/printing the data

    fetch("http://mydinners.fr:5280/partner")
    .then(res => res.json())
    .then(json => {
      let binary = new Uint8Array(json.message[0].partner_image)
      let blob = new Blob([binary])
      let img = new Image()
      img.src = URL.createObjectURL(blob)
      document.body.appendChild(img)
    })

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)