How to post a file and return the status with HTTParty
<p>This works for me in shell:</p>

<pre><code>export TOKEN='eyJqdGkiOiIzZDkzNz'
curl https://apis.xxxxxxxx.com/v2-beta/media \
    --header "Authorization: Bearer $TOKEN" \
    --form 'configuration={"configuration" : {"executor": "v2"}}' \
    --form media="@recording.mp3" \
    | tee media-post-response.json | jq '.'
export MEDIA_ID=$( jq --raw-output '.mediaId' &lt; media-post-response.json )
echo "Uploaded file with mediaId = ${MEDIA_ID}"
</code></pre>

<p>I want to do the same thing with HTTParty,  however, I can find no example anywhere that shows how these headers should be specified.</p>

<p>Here is what I have, but it throws a JSON error:</p>

<pre><code>require 'httparty'
require 'json'
require 'pp'

token = "6Ijg3ZDMzODUxLTdlMmMtN"


url = "https://apis.xxxxxxxx.com/v2-beta/media"

options = {
    :headers =&gt; {"Authorization" =&gt; " Bearer #{token}", "Content-Type" =&gt; "multipart/form-data" , "Accept" =&gt; "application/json"},
    :body =&gt; {"media" =&gt; '@recording.mp3'}
    }
puts "*****  #{options}  ******\n"

j = HTTParty.post(url, options)
s = JSON.parse(j.body)
pp s
</code></pre>

<p>The error is:</p>

<pre><code>(error) .rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/json/common.rb:156:in `parse': 784: unexpected token at 'Failed to create MuleMessage (org.mule.api.lifecycle.CreateException)' (JSON::ParserError)
</code></pre>