1 回答

TA貢獻1806條經驗 獲得超5個贊
您聲稱 Spotify 個人資料圖片是ISO 8850-1編碼/加密的說法毫無意義。
更有意義的是它是 Base64 編碼的。
例如,
面向開發人員的 Spotify:Web API:上傳自定義播放列表封面圖片。
Base64 編碼的 JPEG 圖像數據,最大負載大小為 256 KB
在圍棋中,
包base64
import "encoding/base64"
base64 包實現了 RFC 4648 指定的 base64 編碼。
另一個證據:“UTF-8 格式的 HTTPS 請求”
面向開發人員的 Spotify:Web API
要求
Spotify Web API 基于 REST 原則。通過以 UTF-8 格式向 API 端點發送標準 HTTPS 請求來訪問數據資源。
例如。使用您的 Stack Overflow 個人資料圖片:
package main
import (
? ? "encoding/base64"
? ? "fmt"
? ? "io/ioutil"
? ? "net/http"
? ? "os"
)
func grabImageBytes(imageURL string) ([]byte, error) {
? ? req, err := http.NewRequest("GET", imageURL, nil)
? ? if err != nil {
? ? ? ? return nil, err
? ? }
? ? res, err := http.DefaultClient.Do(req)
? ? if err != nil {
? ? ? ? return nil, err
? ? }
? ? defer res.Body.Close()
? ? body, err := ioutil.ReadAll(res.Body)
? ? if err != nil {
? ? ? ? return nil, err
? ? }
? ? enc := base64.StdEncoding
? ? img := make([]byte, enc.EncodedLen(len(body)))
? ? enc.Encode(img, body)
? ? return img, nil
}
func main() {
? ? imageURL := `https://lh5.googleusercontent.com/-P8ICR-LXoBs/AAAAAAAAAAI/AAAAAAAAE04/fVAeB6_nMeg/photo.jpg?sz=328`
? ? img, err := grabImageBytes(imageURL)
? ? if err != nil {
? ? ? ? fmt.Fprintln(os.Stderr, err)
? ? ? ? return
? ? }
? ? fmt.Println(string(img))
}
- 1 回答
- 0 關注
- 143 瀏覽
添加回答
舉報