Posting photoset with Jumblr (java)

148 views
Skip to first unread message

omrii

unread,
Feb 8, 2018, 9:21:51 PM2/8/18
to Tumblr API Discussion
Hello!
I'm trying to post a photo-set on my tumblr blog and the documentation is confusing me.
It states that when I submit the request, the "data" data type should be

"Array (URL-encoded binary contents)".

I guessed that this means that I have to convert my image into bytes and store it as an array of bytes and pass that as an argument but I'm getting a "Bad Request" exception.

(Exception in thread "main" com.tumblr.jumblr.exceptions.JumblrException: Bad Request)


Here's my method:


public static void postToTumblr(List<String> post_imagePath, String post_source, String post_caption)
{
        // Using only the first image in the ArrayList for the sake of testing...       
       
File initialFile = new File(post_imagePath.get(0));
       
InputStream targetStream = new FileInputStream(initialFile);
       
byte[] image = IOUtils.toByteArray(targetStream);
       
       

       
params.clear();
       
params.put("type", "photo");
       
params.put("caption", post_caption);
       
       
params.put("data", image);
       
       
params.put("source_url", post_source);
       
params.put("source_title", post_source);
       
params.put("source", post_source);
       
        client
.postCreate("blogname.tumblr.com", params);
}


What do I pass in for the data field to get it to post multiple images??

omrii

unread,
Feb 12, 2018, 1:53:58 PM2/12/18
to Tumblr API Discussion
bump!

omrii

unread,
Feb 16, 2018, 3:59:52 AM2/16/18
to Tumblr API Discussion
Bump again. Still doesn't work. I figured perhaps I'd pass an array of strings and decode the URL into UTF-8 but it still doesn't work.

Help would be greatly appreciated!

        Map<String, Object> params = new HashMap<String, Object>();
       
       
JumblrClient client = new JumblrClient("excluded for obvious reasons", "excluded for obvious reasons");
        client
.setToken("excluded for obvious reasons", "excluded for obvious reasons");

       
String[] imageURLs = new String[2];
        imageURLs
[0] = "https://78.media.tumblr.com/d3a9b602f741a28656055cfc87045a9e/tumblr_okzukx7uEF1smipnlo1_1280.jpg";
        imageURLs
[1] = "https://78.media.tumblr.com/154bfb8cdc66e0b4c95c9f649b1246ea/tumblr_okzukx7uEF1smipnlo2_1280.jpg";

       
for(int i = 0; i < imageURLs.length; i++)
       
{
            imageURLs
[i] = URLEncoder.encode(imageURLs[i], "UTF-8");  
       
}
       
       
//Get the post

       
params.clear();
       
params.put("type", "photo");


       
params.put("data", imageURLs);
       
        client
.postCreate("my blog url here", params);

Exception in thread "main" com.tumblr.jumblr.exceptions.JumblrException: Bad Request
    at com.tumblr.jumblr.request.RequestBuilder.clear(RequestBuilder.java:151)
    at com.tumblr.jumblr.request.RequestBuilder.postMultipart(RequestBuilder.java:57)
    at com.tumblr.jumblr.JumblrClient.postCreate(JumblrClient.java:370)
    at Program.Driver.main(Driver.java:49)

omrii

unread,
Feb 16, 2018, 3:04:55 PM2/16/18
to Tumblr API Discussion
I tried again this morning using an ArrayList of type Photo and it still doesn't work...
Reply all
Reply to author
Forward
0 new messages