简体   繁体   中英

Upload track to SoundCloud with javascript API respond Internal Server Error

I'm trying to upload a track to SoundCloud via JAVASCRIPT API, with this code:

<!DOCTYPE html>
<html>
<head>
  <title>Upload track</title>
  <script src="https://connect.soundcloud.com/sdk/sdk-3.0.0.js"></script>
  <script>
    var blob = "MY_BLOB";
    SC.initialize({
      client_id: 'MY_CLIENT_ID',
      oauth_token: 'MY_TOKEN',
      refresh_token: 'MY_REFRESH_TOKEN'
    });
    var upload = SC.upload({
      file: blob, // a Blob of your WAV, MP3...
      title: 'HTML test',
      genre: 'Electronic',
      description: 'This is a good! track'
    });
  </script>
</head>
<body>

</body>
</html>

I get the oauth_token and refresh_token from a previous request. The response I get is:

{"errors":[{"error_message":"500 - Internal Server Error"}]}

I thought that my blob was incorrect, but if I put it in an audio tag:

<audio controls>
  <source src="MY_BLOB" type="audio/ogg">
</audio>

and it works. That is to say the blob not is the problem. What is the problem?

You should try as per

<script src="https://connect.soundcloud.com/sdk/sdk-3.0.0.js"></script>
<script>

// When you have recorded a song with the SDK or any Web Audio application,
// you can upload it if it's in a format that is accepted
SC.upload({
  file: theBlob, // a Blob of your WAV, MP3...
  title: 'This is my sound'
});
</script>

Source = https://developers.soundcloud.com/docs/api/guide#uploading

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM