Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are very close. Check the <strong>class type</strong> of <code>params[:uploaded_file]</code>, it should typically be either a <a href="http://ruby-doc.org/stdlib/libdoc/stringio/rdoc/classes/StringIO.html" rel="noreferrer"><code>StringIO</code></a> or a <a href="http://ruby-doc.org/stdlib/libdoc/tempfile/rdoc/classes/Tempfile.html" rel="noreferrer"><code>Tempfile</code></a> object -- both of which already act as files, and can be read using their respective <code>read</code> method(s).</p> <p>Just to be sure (the class type of <code>params[:uploaded_file]</code> may vary depending on whether you are using Mongrel, Passenger, Webrick etc.) you can do a slightly more exhaustive attempt:</p> <pre><code># Note: use form validation to ensure that # params[:uploaded_file] is not null file_data = params[:uploaded_file] if file_data.respond_to?(:read) xml_contents = file_data.read elsif file_data.respond_to?(:path) xml_contents = File.read(file_data.path) else logger.error "Bad file_data: #{file_data.class.name}: #{file_data.inspect}" end </code></pre> <p>If, in your case, it turns out that <code>params[:uploaded_file]</code> is a hash, make sure that you have not mistakingly flipped the <code>object_name</code> and <code>method</code> parameters when invoking <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M001610" rel="noreferrer"><code>file_field</code></a> in your view, or that your server is not giving you a hash with keys like <code>:content_type</code> etc. (in which case please comment on this post with the <code>Bad file_data ...</code> output from <code>development.log</code>/<code>production.log</code>.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload