11 Jun
FAILSAFE “bad content type” when POSTing multipart data in Rails
My coworker and I spent way too much time on this issue.
The task: Post an image from a Flash/ActionScript frontend to a Rails controller, populating an attachment_fu model. After several attempts, we kept getting the same result: A FAILSAFE error (”bad content type”) called from read_multipart. Here is the stack trace:
The controller’s create action simple populates the appropriate file field like so:
@dog_image.uploaded_data = params[:dog_image]
So what was going on? Well, the “bad content type” message was informative, but barely so. It turns out that the multipart data being POSTed from the SWF was malformed, and Rails didn’t like that. Only one of the many ActionScript multipart libraries seems to use proper formatting, and that one is MultipartURLLoader, as described in this post.
I had to write this post in the hopes that someone will benefit from it, as it took many hours of research to figure this out!
