Friday, January 22, 2010

Drupal for iPhone app Update - Upload Images to Drupal from iPhone

This one took a while to figure out...

Step 1) Create the File.Save Service
Drupal will accept your image encoded as base64 and dump into an actual file.
http://drupal.org/node/376226

Step 2) The iPhone will take a picture and then encode it as base64. I figured out that although the CocoaXMLRPC library will send the XMLRPC response with < base64 > tags, drupal doesn't know what to do with the info in those tags. This created a lot of 0 byte files.
The solution is to comment out the < base64 > tag in the CocoaXMLRPC and substitute < string > tag.

If everything works, you'll get a File ID (fid) back.

So construct your XMLRPC Request like you would with a text content type. Then set your Imagedata as one of the PostParams with the forkey 'file' and the method file.save.

1 comment:

Unknown said...

Hey mate,
you did a great job with the app!!!
Unfortunately I can't download the code, it seems that the link doesn't work anymore.

Can you be so kind to share it again?

Thanks in advance!!!

Andrea