Skip to content

Commit

Permalink
Finish #4 Multiple media uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
mynetx committed May 26, 2014
2 parents 25e00ad + e41b703 commit b998f51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ codebird-cors-proxy - changelog
===============================

1.3.0 (not yet released)
+ #4 Allow uploading multiple media (use media_data)

1.2.3 (2013-12-26)
+ #3 Whitelist rate-limiting headers in CORS
Expand Down
11 changes: 9 additions & 2 deletions codebird-cors-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ function http_get_request_body()
$body = http_get_request_body();

// check for media parameter
// TODO support multiple media[] params after Twitter allows them
// for uploading multiple medias, use media_data, see
// https://dev.twitter.com/docs/api/multiple-media-extended-entities

if (isset($_POST['media']) && is_array($_POST['media'])) {
$body = $_POST;
Expand Down Expand Up @@ -171,7 +172,13 @@ function http_get_request_body()
header('HTTP/1.1 412 Precondition failed');
die('This proxy only supports requests to API version 1.1.');
}
$url = 'https://api.twitter.com' . substr($url, $version_pos);
// use media endpoint if necessary
$is_media_upload = strpos($url, 'media/upload.json') !== false;
if ($is_media_upload) {
$url = 'https://upload.twitter.com' . substr($url, $version_pos);
} else {
$url = 'https://api.twitter.com' . substr($url, $version_pos);
}

// send request to Twitter API
$ch = curl_init($url);
Expand Down

0 comments on commit b998f51

Please sign in to comment.