问题
I am attempting to send a post request to the /tracks endpoint to upload an mp3 audio.
In the apigee console, asset_data parameter is a header. However I do not understand what I am supposed to do with this parameter. Why would I be sending raw data in the headers? That would be in the POST body.
Here is my demo code, HTML, the upload function is the only relevant part of the code (but again the same thing happens here https://apigee.com/console/soundcloud)
function upload(blob){
var auth = "Bearer 1-122377-144392358-af3f9a82d0e0e";
var myUrl = "https://api.soundcloud.com/tracks?client_id=30f3ce7853003c7bdf6445b7a15505d5";
var fd3 = new FormData();
fd3.append("track[title]", 'my title');
fd3.append("track[asset_data]", blob);
fd3.append("oauth_token", '1-122377-144392358-af3f9a82d0e0e');
fd3.append("format", "json")
fd3.append("Filename", "blob.mp3")
$.ajax({
type:"POST",
beforeSend: function (request)
{
request.setRequestHeader("Authorization", auth);
},
url:myUrl,
data:fd3,
//timeout:10000,
processData: false,
contentType: false,
success: function(data) {
console.log("SOUNDCLOUD", data);
},
error: function(shr, status, data) {
console.log("SOUNDCLOUD", shr.status, status, data);
}
});
}
回答1:
OK i figured it out by doing a network sniff on the official javascript recording api, and used that as a template. But I have to say the api documentation is not very good for this endpoint. there is not mention that asset data should be "track[asset_data]"
Also the apigee console needs to be fixed. asset_data is not a header.
来源:https://stackoverflow.com/questions/32159979/soundcloud-http-api-post-tracks-422-unprocessable