我在一个私有的node.js项目中,服务器上应该有一个端点来更新特定播放列表的封面图片。在这个端点里面我有这样的代码。
let playlistID = '7fOfY.......G5RFK3z'; // ID of already created playlist
let imgFile = '/9j/4AAQSkZJRg.......AgICAg'; // data:image/jpeg;base64
let spotifyAccessToken = 'DHdhw3.......DHdfLS8'; // valid access token
let options = {
url: 'https://api.spotify.com/v1/playlists/' + playlistID + '/images',
headers: {
'Authorization': 'Bearer ' + spotifyAccessToken,
'Content-Type': 'image/jpeg'
},
body: imgFile
}
request.put(options,(error, response) => {
if(response.statusCode === 202) {
console.log('Upload cover');
} else {
console.log(JSON.stringify(response));
}
在终端中,它总是失败,Spotify中没有封面图片。有谁知道是什么问题吗?我该怎么做才能解决这个问题?https:/developer.spotify.comdocumentationweb-apireferenceplaylistsupload-custom-playlist-cover
EDIT:
Response object looks like this:
{"statusCode":400,
"body":{
"error": {
"status": 400,
"message": "Bad request."
}
},
"headers":{
"content-type": "application/json; charset=utf-8",
"cache-control": "private",
"max-age=0",
"access-control-allow-origin":"*",
"access-control-allow-headers":"Accept, App-Platform, Authorization, Content-Type, Origin, Retry-After, Spotify-App-Version, X-Cloud-Trace-Context",
"access-control-allow-methods":"GET, POST, OPTIONS, PUT, DELETE, PATCH",
"access-control-allow-credentials":"true",
"access-control-max-age":"604800",
"content-length":"72",
"date":"Fri, 24 Jan 2020 09:29:49 GMT",
"via":"1.1 google",
"alt-svc":"clear",
"connection":"close"
},
"request":{
"uri":{
"protocol":"https:",
"slashes":true,
"auth":null,
"host":"api.spotify.com",
"port":443,
"hostname":"api.spotify.com",
"hash":null,
"search":null,
"query":null,
"pathname":"/v1/playlists/7fOf.....FK3z/images",
"path":"/v1/playlists/7fOf.....FK3z/images",
"href":"https://api.spotify.com/v1/playlists/7fOf.....FK3z/images"
},
"method":"PUT",
"headers":{
"Authorization":"Bearer BQDBBS2T......CZVtcz70",
"Content-Type":"image/jpeg",
"content-length":0}
}
}
https:/www.base64decode.org 我从 此职位 可能有助于确保你的有效载荷正确解码为图像,你可以把base64字符串放在一个文本文件中,然后上传到这个网站,看看它是否能解码为你想要的图像。
如果你还没有这样做的话,从base64字符串的开头省略 "data:imagejpeg;base64 "也会有帮助。