Media/upload throwing "unrecognized" error every time

media

#1

I’m trying to upload images via the api (using npm twit) and getting this back from api each time:

 { [Error: Unknown Twitter API Error]
    message: 'Unknown Twitter API Error',
    statusCode: 400,
    twitterReply: '{"request":"\\/1.1\\/media\\/upload.json","error":"media type unrecognized."}',
    code: null,
    allErrors: []
}

I read a possible reason could be file size, but my files are ~40kb . I’ve tried lots of different images and none of them have worked, all with the same error thrown.

Am I doing something wrong? I’ve tried using {media: base64_data} and {media_data: base64_data}

I’m using .jpg and .png images only.


#2

Another “possible” reason is you are not authenticated.


#3

possible, but i am able to post a status update directly after i try a media/upload. can i verify authentication and/or authorization via the api?


#4

If you can post then you are authenticated. You will have to dig deeper into your code. But, to answer your question, from Twitter’s error message, yes, it looks like you are doing something wrong.


#5

Same error occured 2-3 days ago. During investigation, one was detected invalid value in Content-Length header during [POST /1.1/media/upload.json] request. For example, picture was 530 kb, but Content-Length was set to ~500kb for unknown reason.

During fixing, all http-related code of media uploading routines was rewritten using direct plain calls to http-client library, without any 3rd-party helpers/wrappers, and problem gone away.


#6

i figured it out!

my app was downloading an image from the web, then trying to upload it to twitter via the API. the problem was that it was trying to upload the file before it was written to disk.

i implemented fibers/future to make sure the file is completely written before trying to upload and it works perfectly.

thanks for your input and suggestions, it helped to know for sure that it was me and not the api.


#7