In the hopes of sparing another unfortunate soul from suffering the wrestling match I&#39;ve been having this week...<div><br></div><div><br></div><div>SYMPTOM: Regardless of how many upload-file fields you have in your form, Catalyst doesn&#39;t see the file uploads. That is, <b>$c-&gt;req-&gt;uploads</b> is an empty hash?! And <b>$c-&gt;req-&gt;upload</b> is an empty array?! File uploads are not working at all!</div>
<div><br></div><div>Let&#39;s say you develop a form that works just fine, and then you add an upload field. Everything else still works as before, but the uploads are ignored: <b>$c-&gt;req-&gt;uploads</b> is an empty hash (and <b>$c-&gt;req-&gt;upload</b> is an empty array). You can see some of the details in <b>$c-&gt;req-&gt;_body</b> but there&#39;s no uploaded info to work with! You can&#39;t get the uploaded file from /tmp/blahblahblah because there isn&#39;t any such uploaded file. You can&#39;t see the size or the content or the mime-type. It&#39;s as if nothing is uploaded at all.<br>
<div><br></div><div><br></div><div>SOLUTION: To deal with uploaded files, your form must use &quot;<b>multipart/form-data</b>&quot;! It&#39;s not Catalyst&#39;s fault, your web browser behaves differently depending on the &lt;form&gt; attributes you specified. Here&#39;s the primary snippet to add when using HTML::FormHandler...</div>
<div><br></div><div>{</div><div>    package MyApp::Form::UploadForm;</div><div><div>    use HTML::FormHandler::Moose;</div><div>    extends &#39;HTML::FormHandler::Model::DBIC&#39;;</div><div>    with &#39;HTML::FormHandler::Render::Table&#39;;</div>
</div><div><br></div><div><meta charset="utf-8"><div><div>    has &#39;+item_class&#39; =&gt; ( default =&gt; &#39;RecordSpecHere&#39; );</div></div></div><div><br></div><div><div><span class="Apple-style-span" style="background-color: rgb(255, 255, 153);">    # MULTIPART/FORM-DATA is MANDATORY for file-uploads, beware!</span></div>
<div><span class="Apple-style-span" style="background-color: rgb(255, 255, 153);"><b>    has &#39;+enctype&#39; =&gt; ( default =&gt; &#39;multipart/form-data&#39; );</b></span></div><div><div><br></div><div><div>    has_field &#39;id&#39;        =&gt; ( type =&gt; &#39;Hidden&#39;, );</div>
</div></div><div>#...<br>    has_field &#39;myfile&#39; =&gt; ( type =&gt; &#39;Upload&#39; );<br>}<br><br></div><div><br></div><div>At any rate, your form tag will now look a bit like this:</div><div><br></div><div>&lt;form enctype=&quot;<b>multipart/form-data</b>&quot; method=&quot;<b>post</b>&quot; id=&quot;form996&quot;&gt;</div>
<div><br></div><div>Single-stepping through the Perl debugger will now show that Catalyst has everything you need in <b>$c-&gt;req-&gt;uploads</b>:</div><div><br></div><div><div>DB&lt;3&gt; <b>x $c-&gt;req-&gt;uploads</b></div>
<div>0  HASH(0xc54f598)</div><div>   &#39;myfile&#39; =&gt; Catalyst::Request::Upload=HASH(0xc56d858)</div><div>      &#39;filename&#39; =&gt; &#39;sample-file.txt&#39;</div><div>      &#39;headers&#39; =&gt; HTTP::Headers=HASH(0xc56d918)</div>
<div>         &#39;content-disposition&#39; =&gt; &#39;form-data; name=&quot;myfile&quot;; filename=&quot;sample-file.txt&quot;&#39;</div><div>         &#39;content-type&#39; =&gt; &#39;application/octet-stream&#39;</div>
<div>      &#39;size&#39; =&gt; 74</div><div>      &#39;tempname&#39; =&gt; &#39;/tmp/BqoVhCmj3f&#39;</div><div>      &#39;type&#39; =&gt; &#39;text/plain&#39;</div></div><div><br></div><div>Woo hoo!</div><div><br></div><div>
<br></div>-- <br>Failure is not important. How you overcome it, is.<br>-- Nick Vujicic<br>
</div></div>