2017-07-20 99 views
0

如何使用數據庫中的base64字符串顯示圖像?我看不到任何函數可以通過使用jQuery DataTable來轉換。如何使用數據庫中的base64字符串顯示圖像

oTableImage = $('#tbl_image').DataTable({ 
     "processing": true,    
     "destroy": true, 
     "paging":false, 
     "bFilter": false, 
     // "scrollY": "200px", 
     "ajax":{ 
      "type":"POST", 
      dataType: "json", 
      "url":"{{ URL::to('ajax/per-seller-image') }}", 
      "data":function(d){ 
       d.rtd_id =rtd; 
      } 
     }, 

     "columns":[ 
      {data: 'start_image', name: 'start_image'} 
     ] 
    }); 
}); 
+0

我可以問服務器端正在使用什麼嗎?使用'data:image'可能不是要走的路。在服務器上創建一個處理程序來提供圖像的二進制內容而不是返回base64數據可能更明智。 –

回答

1

您可以顯示在HTML這樣的base64編碼的圖像:

<img src="data:image/png;base64,xxxxxxxxxxBASE64_HASHxxxxxxxx==="> 

然後渲染DataTable中的<img>標籤:

"columns": [ 
    { 
     "render": function (data, type, row) { 
      return '<img src="data:image/png;base64,' + row.start_image + '">'; 
     } 
    } 
], 
0

Base64編碼數據將被瀏覽器自動呈現本身。你不必轉換。

相關問題