Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to read a User uploaded file, without saving it to the database
    primarykey
    data
    text
    <p>I'd like to be able to read an XML file uploaded by the user (less than 100kb), but not have to first save that file to the database. I don't need that file past the current action (its contents get parsed and added to the database; however, parsing the file is not the problem). Since local files can be read with:</p> <pre><code>File.read("export.opml") </code></pre> <p>I thought about just creating a file_field for :uploaded_file, then trying to read it with</p> <pre><code>File.read(params[:uploaded_file]) </code></pre> <p>but all that does is throw a TypeError (can't convert HashWithIndifferentAccess into String). I really have tried a lot of various things (including reading from the /tmp directory as well), but could get none of them to work. </p> <p>I hope the brevity of my question doesn't mask the effort I've given to try to solve this on my own, but I didn't want to pollute this question with a hundred ways of how NOT to get it done. Big thanks to anyone who chimes in.</p> <p>Here is my view:</p> <pre><code>&lt;% form_for(:uploaded_file, @feed, :url =&gt; {:action=&gt;'parse'}, :html=&gt; {:multipart=&gt;true}) do |f| %&gt; &lt;p&gt; &lt;%= f.label :uploaded_file, 'Upload your file.' %&gt;&lt;br /&gt; &lt;%= f.file_field :uploaded_file %&gt; &lt;/p&gt; &lt;p&gt;&lt;%= f.submit 'upload' %&gt;&lt;/p&gt; &lt;% end %&gt; </code></pre> <p>I set up a custom action (upload) which handles the file_field upload, which after submission, is passed off to another custom action (parse) for processing. Could this be a part of my problem?</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. 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