wood burning stoves 2.0*
The moose likes Java in General and the fly likes Sending a photo to the tumblr API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Sending a photo to the tumblr API" Watch "Sending a photo to the tumblr API" New topic
Author

Sending a photo to the tumblr API

Nigey Nige
Greenhorn

Joined: Jul 07, 2011
Posts: 1
So I've been wrestling with this problem for a while, trying to code my first network-enabled app. The purpose of my program is to upload a directory of images to the user's blog using the Tumblr API, found here.


The Write API is a very simple HTTP interface. To create a post, send a POST request to http://www.tumblr.com/api/write with the following parameters:

email - Your account's email address.
password - Your account's password.
type - The post type.
(content parameters) - These vary by post type.



These are the valid values for the type parameter, with the associated content parameters that each type supports:

regular - Requires at least one:
-title
-body (HTML allowed)
photo - Requires either source or data, but not both. If both are specified, source is used.
-source - The URL of the photo to copy. This must be a web-accessible URL, not a local file or intranet location.
-data - An image file. See File uploads below.
-caption (optional, HTML allowed)
-click-through-url (optional)



File uploads can be done in a data parameter where specified above. You may use either of the common encoding methods:

multipart/form-data method, like a file upload box in a web form. Maximum size:
-50 MB for videos
-10 MB for photos
-10 MB for audio
This is recommended since there's much less overhead.
Normal POST method, in which the file's entire binary contents are URL-encoded like any other POST variable. Maximum size:
-5 MB for videos
-5 MB for photos
-5 MB for audio


So I read up on how to perform POST requests, and I managed to send a text post successfully to my blog with the following code:



That works wonderfully. The problem I face now is how to add an image as the data parameter for the post type photo. I've tried what feels like everything, but all I get are 400 bad request errors.

Here's my ImagePost class at the moment, but it's gone through so many iterations of trial and error that it no longer makes any sense to me. Can anyone explain to me how I go about this?

Abhay Agarwal
Ranch Hand

Joined: Feb 29, 2008
Posts: 1076
    
    1

I have not used Tumblr API before but just want to add -
I guess you are not encoding your data parameter(image).
As per API, data parameter should be image file and it has to be encoded also.

~ abhay


Oracle Java Web Service Developer (1z0-897), Oracle certified Java 7 Programmer, SCJA 1.0, SCJP 5.0, SCWCD 5.0, Oracle SQL Fundamentals I
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sending a photo to the tumblr API
 
Similar Threads
HTTPS Post Request through the URL
post request to url
POST data with a file upload
error while submitting an http web request
core java communicates with servlet or jsp?