REST API 1.1 update_with_media.json always returns code 500 and {"errors":[{"message":"Internal error","code":131}]} from Objective-C app


#1

I’m trying to upload a picture on Twitter from a Mac app, using REST API 1.1 (url: https://api.twitter.com/1.1/statuses/update_with_media.json), but I get always error code 500 and {“errors”:[{“message”:“Internal error”,“code”:131}]}. If I upload only a tweet (using /update.json) it works fine every time.

Here is my code:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0f];
[request setHTTPMethod:@"POST"];
[request setHTTPShouldHandleCookies:NO];

NSString *boundary = @"64F3EC90-E32B-4BD9-ADB4-E1A9FBE4AFD6";

NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary];
[request setValue:contentType forHTTPHeaderField:@"Content-Type"];

[self signRequest:request];  // Adding Oauth

NSMutableData *body = [NSMutableData dataWithLength:0];

// Adding tweet string
[body appendData:[[NSString stringWithFormat:@"--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
NSData *data = [[NSString stringWithFormat:@"%@\r\n",@"Uploading again test3"]dataUsingEncoding:NSUTF8StringEncoding];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n",@"status"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:data];

// Adding image
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"media[]\"; filename=\"test.jpg\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: image/jpeg\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Transfer-Encoding: binary\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:imageData];

[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];

// Set HTTPBody
[request setValue:@(body.length).stringValue forHTTPHeaderField:@"Content-Length"];
request.HTTPBody = body;

#2

Hello Pantiru,

Sorry for the late reply here. The engineers identified an issue last month and actually resolved it a few days after your post, so these errors should no longer be occurring.

Please let us know if you encounter any further issues with [node:9708].

Thanks,
Romain


#3

Hi @romainhuet looks like the issue still exists. I got the same response status and error message while making upload media call. The difference is I used browser JavaScript to upload the base64 image format.