Wondering how I could implement an upload controller like the Basecamp API, where you can upload a file attachment, receive an XML response containing an ID for that photo, then use that to reference the file in a subsequent XML post to attach the XML record to the file attachment...
Basically all you need is a plugin that manages the uploaded file, like Paperclip or Attachment_fu. These plugins allow to interact with the files as you would a database record, so there will be an id attached to each file.
Then make sure that you have a xml declaration in the respond_to
block in your controller.
respond_to do |format|
format.html
format.xml { #return the id for the file }
end
Surprising that there is apparently no documentation for doing this anywhere to be found. I ended up stumbling across a document on the Basecamp website describing how their file attachment process works for API users and used it as a guideline.
http://developer.37signals.com/basecamp/
with help from this article about posting files:
http://www.codevil.com/index.php/2009/05/23/posting-and-getting-files-in-rubyrails/
I modified my initial setup so that, rather than passing the tag in the XML, they first post a file and receive an file ID in response.
Then they post the XML with that reference and their .
Then I use before_validation and after_save callbacks to set the file with Paperclip, and remove the tmp file after the save.