Cannot upload media: {"errors":[{"message":"Over capacity","code":130}]}



Update: Figured out the problem, response post below. tl;dr, “Over capacity” error was a red herring - the multipart/form-data was incorrect.

Creating status updates via statuses/update.json work fine, but media uploads are consistently giving me “Over capacity” errors for every attempt, with or without post content. Posting images normally through works, so my account hasn’t hit a quota yet. Authentication works, AFAIK.

POST contents:

Content-Disposition: form-data; name="media"; filename="gb-bird3.gif"
Content-Type: image/png
Content-Transfer-Encoding: base64


All POST options, as described by print_r ($options):

    [method] => POST
    [header] => Content-type: multipart/form-data; boundary=-----497dd58398bfad23035dae3a3bde5b68
Authorization: OAuth oauth_consumer_key="xxxx", oauth_nonce="5c67193776bfe66af4bec3ee1c1aeb83c66f226a", oauth_signature="xxxx", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1433731692", oauth_token="xxxx", oauth_version="1.0"

    [ignore_errors] => 1
    [content] => (omitted - identical to POST contents above)    

Response headers:

    [0] => HTTP/1.0 400 Bad Request
    [content-length] => 62
    [content-type] => application/json;charset=utf-8
    [date] => Mon, 08 Jun 2015 02:48:07 GMT
    [server] => tsa_a
    [set-cookie] => guest_id=v1%3A143373168718327881;; Path=/; Expires=Wed, 07-Jun-2017 02:48:07 UTC
    [strict-transport-security] => max-age=631138519
    [vary] => Origin
    [x-connection-hash] => 71c9f59a4fd6b7390d0851f5b23c943d
    [x-frame-options] => SAMEORIGIN
    [x-response-time] => 4
    [x-xss-protection] => 1; mode=block

Response content:

{"errors":[{"message":"Over capacity","code":130}]}

Any ideas? Thanks in advance.


Update: Problem isn’t solved yet, but it would appear I didn’t build the multipart/form-data content properly. I added another “–$boundary–” after the image content, and now I’m getting a different error:

{“errors”:[{“code”:32,“message”:“Could not authenticate you.”}]}

For the record, the content for uploading an image called “synival_avatar_48.png” now looks like this:

    [method] => POST
    [header] => Content-type: multipart/form-data; boundary=-----190398db8615fc43ea8dcc2e4a09470b
Authorization: OAuth oauth_consumer_key="xxxx", oauth_nonce="72f168b769d2da6de7c147dd78c224f8815e4618", oauth_signature="xxxx", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1433789816", oauth_token="xxxx", oauth_version="1.0"

    [ignore_errors] => 1
    [content] => -------190398db8615fc43ea8dcc2e4a09470b
Content-Disposition: form-data; name="media"; filename="synival_avatar_48.png"
Content-Type: image/png
Content-Transfer-Encoding: base64

<lots of image data>

It’s likely I’m building the OAuth signature base string improperly for this post, so I’m looking into it. The errors from the Twitter API are vague if not misleading, so I’m mostly working in the dark here. I’m also concerned that I’m still getting an HTTP/1.0 400 Bad Request response in the header - is this because the content is still built wrong, or because Twitter doesn’t like my authentication? I’m admittedly still a newbie when it comes to all this, so any help or corrections would really be appreciated!

Update #2: Fixed it, now I feel dumb. I was indeed building the signature wrong – it was including the multipart/form-data content in the base string, which was completely wrong. Once it was removed, I got a new error:

{“request”:"/1.1/media/upload.json",“error”:“media type unrecognized.”}

…which was fixed by changing name=“media” to name=“media_data” in Content-Disposition. It turns out you need to set your parameters correctly - derp!


I am having the exact same issue, and i have tried following your steps in order to solved them, but so far no luck…

Could you be so kind as to post your full code?

Thanks in advance


Here’s how I build the multipart/form-data content:

// Content for multipart/form-data
$boundary = "-----" . md5 (time ());
$data  = '--' . $boundary . "\r\n";
$data .= 'Content-Disposition: form-data; filename="quadradigger_upload.png"; ' . 'name="media_data"' . "\r\n";
$data .= 'Content-Type: ' . $ctype . "\r\n";
$data .= 'Content-Transfer-Encoding: ' . $cencoding . "\r\n";
$data .= "\r\n" . $cdata . "\r\n";
$data .= '--' . $boundary . "--\r\n";

Take note of the double-dash strings (–), that’s what was causing Twitter to complain in my case. If it’s still not working, please post your multipart/form-data content. If it looks like the content is correct, I’ll clean up my extremely messy code and post more :slight_smile:

The “content-type” field for your POST’s header should be:

"multipart/form-data; boundary=$boundary"


Hi I am having the same kinda problem. Could you please check out my code and see where I am going wrong. I would really appreciate it. I have been breaking my head on this for a week now. Please click on this link Upload media endpoint over capacity error.