views:

36

answers:

2

In our rails application we have a many actions that do regular webapp actions. But, we have a single action that accepts a large XML file. I would like to keep rails from parsing the XML into params. Instead, I would like to be able to get the URL params ( /documents/{id}/action ) and then write out the xml file to a specific directory. How do I keep Rails from processing it?

How would I define the action to handle this?

def handle_xml
   # what to put here
end

The upload is done using Content-Type: application/xml It is a single file, and not part of a multipart form. The sample curl statement would be:

curl-H 'Accept: application/xml' -H 'Content-Type: application/xml' -X POST -d '<?xml version="1.0" encoding="UTF-8"?><test></test>' http://0.0.0.0:3000/controller/handle_xml
A: 

The action should receive it as a file (through way of multipart form upload) and then store it as a temporary file for you.

Ryan Bigg
What about if the file is being received as Content-type: application/xml Is there a way to keep it from processing it? This means it isn't part of a multi-part form.
christophercotton
A: 

Have you tried sending the xml file has one variable in the http uri request? So something like

@xml_file = xml..xml...xml...

parameters => {
  query => {
    xml_file => @xml_file
  }
}
Httparty.post("url", parameters)

Then in your method:

def handle_xml
  @xml_file = params[:xml_file]
  @xml_file.save (or whatever you want here..)
end
Nick
What about if the file is being received as Content-type: application/xml Is there a way to keep it from processing it? This means it isn't part of a multi-part form.
christophercotton
good question... isn't there a way to just fool the program and say its not xml... I'll have to look into that.
Nick
You can always do a output = Hash.from_xml(@xml_file), then back_to_xml = output.to_xml
Nick