# Multipart REST post, XML body with file

**URL:** <https://www.ruby-forum.com/t/multipart-rest-post-xml-body-with-file/164997>\
**Category:** Rails\
**Created:** [April 8, 2009, 6:29am UTC](https://www.ruby-forum.com/t/multipart-rest-post-xml-body-with-file/164997 "2009-04-08T06:29:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![e\_deleflie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/858c86/32.png) [@e\_deleflie](https://www.ruby-forum.com/u/e_deleflie)\
**Post date:** [April 8, 2009, 6:29am UTC](https://www.ruby-forum.com/t/multipart-rest-post-xml-body-with-file/164997/1 "2009-04-08T06:29:15Z")

</div>

Hi,

Can anyone shed light on how to do a classic RAILS REST POST (i.e.  
post an XML structure representing an ActiveResource) … whilst at  
the same time posting a file?

My current code (working) is below. It does not have a file associated  
with the post.

I know I have to do a multipart, but what I cant work out is that in a  
multipart, each value has a key … what would be the key for the main  
XML body? Because, see, in the example below, the XML _is_ the body  
… it has no key associated with it.

Etienne

* * *

body = “\<?xml version=“1.0”  
encoding=“UTF-8”?\>\<my\_object\>\<someValue  
type=“boolean”\>true3456\</someOtherValue\</my\_object\>”

```
uri = URI.parse("http://#{$SITE_URL}/my_object.xml")
http = Net::HTTP.new(uri.host, uri.port)
headers={}
headers['Content-Type'] = "application/xml"

begin
  http.start do
    req = Net::HTTP::Post.new(uri.request_uri, headers)
    req.basic_auth($name, $pword)
    resp = http.request(req, body)

    if resp.is_a?(Net::HTTPSuccess)
      return true
    else
      return false
    end

  end
rescue Exception => e
  debug "Exception with submitting using net:http #{ e } (#{ e.class 

```

})!"  
return false  
end
