I'm trying to upload an image to Twitter using their API, but it always fails throwing an error saying it can't find the file even though it's definitely there since I'm using the same path to upload it fine to other networks and it displays correctly in my preview box.
com.twitter.sdk.android.core.TwitterApiException: /-1/1/content:/media/external/images/media/100883/ORIGINAL/NONE/1159437588: open failed: ENOENT (No such file or directory)
W/System.err: at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:390)
W/System.err: at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
W/System.err: at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
W/System.err: at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
W/System.err: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
W/System.err: at java.util.concurrent.FutureTask.run(FutureTask.java:237)
W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
W/System.err: at java.lang.Thread.run(Thread.java:818)
Some Googling showed this error was meant to have been fixed in an older version of the Twitter SDK for Android, and people have confirmed it was, but that was a while ago and I'm using the latest version 1.13.0
.
The code I'm using to upload this is as follows:
//img = Uri passed from calling method
File photo = new File(img.getPath());
TypedFile typedFile = new TypedFile("application/octet-stream", photo);
TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient(twitSession);
MediaService mediaService = twitterApiClient.getMediaService();
final StatusesService statusesService = twitterApiClient.getStatusesService();
mediaService.upload(typedFile, null, null, new Callback<Media>() {
@Override
public void success(final Result<Media> result) {
statusesService.update(input, null, null, null, null,
null, null, null, result.data.mediaIdString, new Callback<Tweet>() {
@Override
public void success(Result<Tweet> result) {
Log.d("Twitter image callback", "Successfully posted image and text to Twitter!");
}
@Override
public void failure(TwitterException e) {
if (result != null) {
Log.e("Twitter image callback", "Result is - " + result.toString());
}
Log.d("Twitter image callback", "Failed to post image and text to Twitter!");
}
});
}
@Override
public void failure(TwitterException e) {
Log.d("Twitter image callback", "Failed to upload image to Twitter!");
e.printStackTrace();
}
});
Does anyone know what went wrong here and how I'm able to get this working?