Posting image with spring social



I’m trying to post a tweet with image which is uploaded in my system. I get response “media type unrecognized”.

public Tweet postTweet(TwitterPost twitterPost) {
        TweetData tweetData = new TweetData(
            twitterPost.getPostText() + "\n" +
            if (nonNull(twitterPost.getImagePath())){
                Resource image = new FileSystemResource(twitterPost.getImagePath());
                tweetData = tweetData.withMedia(image);
      "Trying to tweet with image url {}");
            }"Sending tweet {}");
        return twitter.timelineOperations().updateStatus(tweetData);

When i post with UrlResource and put image url from intertnet it works fine. How i can post a tweet with my own file. Is it even possible or the file has to be reachable from my server with url. What am I doing wrong.


I think you’d have to ask the Spring Social folks about this. The Twitter API supports image uploading, but I don’t know how Spring is implementing this.