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?