Breki Tomasson
Breki Tomasson

Reputation: 207

Soundcloud API Upload suddenly throwing code 422

Been using the PHP Soundcloud API for some time now, and it's been working fine. The code I use to create the track array is (and has always been):

$track = json_decode($client->post('tracks', array(
  'track[title]' => $title,
  'track[asset_data]' => $filename,
  'track[description]' => $desc,
  'track[genre]' => "Podcast",
  'track[artwork_data]' => $image
)));

And it's always been working just fine - until this morning, when I got this error message when uploading a track using my home-made PHP tool:

Fatal error: Uncaught exception 'Services_Soundcloud_Invalid_Http_Response_Code_Exception' with message 'The requested URL responded with HTTP code 422.' in /home/csicon/public_html/PodcastAuthor/lib/Soundcloud.php:943 Stack trace: #0 /home/csicon/public_html/PodcastAuthor/lib/Soundcloud.php(621): Services_Soundcloud->_request('https://api.sou...', Array) #1 /home/csicon/public_html/PodcastAuthor/2-publish.php(52): Services_Soundcloud->post('tracks', Array) #2 {main} thrown in /home/csicon/public_html/PodcastAuthor/lib/Soundcloud.php on line 943

Now, I'm no newb, and know what HTTP code 422 is all about, so I checked the contents of $title, $filename, $desc and $image. They are, in order:

Geekdays #274: 2015-11-17

@/home/csicon/public_html/PodcastAuthor/uploads/g274.mp3

Snowden, the FBI and the Oxford Dictionary are getting blamed for things that they may or may not have done. Also; the air you're breathing might be killing you. This, and so much more, on today's episode of Geekdays.

@/home/csicon/public_html/wp-content/uploads/2014/10/geekdays-600x600.png

All paths (to the mp3 and the image) check out, there's nothing wonky in the character set being used, and it's all worked before. What might have happened here? I'm stumped.

UPDATE! Turns out my webhost has upgraded their PHP environment from 5.4 to 5.6, and this is what broke it. What's changed between 5.4 and 5.6 that might have caused this, in that case?

Upvotes: 2

Views: 406

Answers (2)

Breki Tomasson
Breki Tomasson

Reputation: 207

Magically started working when I changed to the sebdesign/php-soundcloud version of the curl-file branch. Not sure why the "normal" curl-file branch didn't work, however.

Upvotes: 0

C3roe
C3roe

Reputation: 96306

Turns out my webhost has upgraded their PHP environment from 5.4 to 5.6, and this is what broke it. What's changed between 5.4 and 5.6 that might have caused this, in that case?

How cURL file uploads are handled has changed.

CURLOPT_SAFE_UPLOAD is set to true by default from PHP 5.6 on, and that means file uploads are not possible any more using the @-file path syntax, but CURLFile should be used for file uploads instead.

Try setting CURLOPT_SAFE_UPLOAD to false, using the setCurlOptions method.

Upvotes: 0

Related Questions