[問題] 顯示JPG問題
各位大大好
小弟向一個server要了一個JPG回來
回應的Body是multipart 如下圖
https://imgur.com/tUMbpow
切掉不必要的東西之後 裡面JPG內容是以text格式呈現
想請教該如何將這樣的內容轉換成Blob
好讓我用URL.createObjectURL的方式塞到<img>裡
或是這樣的轉換該用甚麼關鍵字去找
簡略的程式碼在這裡
fetch(url, {
method: "GET",
headers: new Headers({
'Accept': 'multipart/related; type="image/jpeg"'
})
})
.then(response => {response.text()})
.then(data => {
//data 轉換 blob
let img = document.getElementsByTagName('img')[0];
img.src =URL.createObjectURL(blob);
})
謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 182.234.77.14
※ 文章網址: https://www.ptt.cc/bbs/Web_Design/M.1542884573.A.077.html
→
11/23 02:29,
5年前
, 1F
11/23 02:29, 1F
→
11/23 02:29,
5年前
, 2F
11/23 02:29, 2F
→
11/23 11:36,
5年前
, 3F
11/23 11:36, 3F
→
11/23 19:11,
5年前
, 4F
11/23 19:11, 4F
→
11/23 19:12,
5年前
, 5F
11/23 19:12, 5F