<p dir="auto">I want to get file list from form by using:</p>
<p dir="auto"><code class="notranslate">photos = request.files.getlist("photo") </code><br>
However if i haven't select anything, the photos value is never be [] like other fields.</p>
<p dir="auto">So the way to check for empty field is failed:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="if not photos:
   pass"><pre class="notranslate"><code class="notranslate">if not photos:
   pass
</code></pre></div>
<p dir="auto">The result for empty form is:<br>
<code class="notranslate"> [&lt;FileStorage: '' ('application/octet-stream')&gt;]</code></p>
<p dir="auto">How do i get rid of it?</p>
<p dir="auto">Issue came up while trying to send an empty file (and filename) to an HTTPbin form.<br>
Using Flask you're unable to differentiate between the content of a text field in a form and a non-uploaded file from the <code class="notranslate">request</code> object</p>
<h3 dir="auto">Example test</h3>
<p dir="auto">Using flask alone;<br>
User <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/moy/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/moy">@moy</a> helped with this and prompted me to post this bug report</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="from flask import Flask, flash, request, redirect, url_for, escape

app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
def upload_file():
    if request.method == 'POST':
        return '&lt;pre&gt;{}&lt;/pre&gt;'.format(escape(str(request.form) + '\n' + str(request.files)))
    return '''
    &lt;!doctype html&gt;
    &lt;title&gt;Upload new Files&lt;/title&gt;
    &lt;h1&gt;Upload new Files&lt;/h1&gt;
    &lt;form method=post enctype=multipart/form-data&gt;
      &lt;input name=&quot;normal_field&quot; value=&quot;field_value&quot; /&gt;
      &lt;input type=file name=file&gt;
      &lt;input type=file name=secondfile&gt;
      &lt;input type=submit value=Upload&gt;
    &lt;/form&gt;
    '''"><pre class="notranslate"><span class="pl-k">from</span> <span class="pl-s1">flask</span> <span class="pl-k">import</span> <span class="pl-v">Flask</span>, <span class="pl-s1">flash</span>, <span class="pl-s1">request</span>, <span class="pl-s1">redirect</span>, <span class="pl-s1">url_for</span>, <span class="pl-s1">escape</span>

<span class="pl-s1">app</span> <span class="pl-c1">=</span> <span class="pl-v">Flask</span>(<span class="pl-s1">__name__</span>)

<span class="pl-en">@<span class="pl-s1">app</span>.<span class="pl-en">route</span>(<span class="pl-s">'/'</span>, <span class="pl-s1">methods</span><span class="pl-c1">=</span>[<span class="pl-s">'GET'</span>, <span class="pl-s">'POST'</span>])</span>
<span class="pl-k">def</span> <span class="pl-en">upload_file</span>():
    <span class="pl-k">if</span> <span class="pl-s1">request</span>.<span class="pl-s1">method</span> <span class="pl-c1">==</span> <span class="pl-s">'POST'</span>:
        <span class="pl-k">return</span> <span class="pl-s">'&lt;pre&gt;{}&lt;/pre&gt;'</span>.<span class="pl-en">format</span>(<span class="pl-en">escape</span>(<span class="pl-en">str</span>(<span class="pl-s1">request</span>.<span class="pl-s1">form</span>) <span class="pl-c1">+</span> <span class="pl-s">'<span class="pl-cce">\n</span>'</span> <span class="pl-c1">+</span> <span class="pl-en">str</span>(<span class="pl-s1">request</span>.<span class="pl-s1">files</span>)))
    <span class="pl-k">return</span> <span class="pl-s">'''</span>
<span class="pl-s">    &lt;!doctype html&gt;</span>
<span class="pl-s">    &lt;title&gt;Upload new Files&lt;/title&gt;</span>
<span class="pl-s">    &lt;h1&gt;Upload new Files&lt;/h1&gt;</span>
<span class="pl-s">    &lt;form method=post enctype=multipart/form-data&gt;</span>
<span class="pl-s">      &lt;input name="normal_field" value="field_value" /&gt;</span>
<span class="pl-s">      &lt;input type=file name=file&gt;</span>
<span class="pl-s">      &lt;input type=file name=secondfile&gt;</span>
<span class="pl-s">      &lt;input type=submit value=Upload&gt;</span>
<span class="pl-s">    &lt;/form&gt;</span>
<span class="pl-s">    '''</span></pre></div>
<h3 dir="auto">Expected Behavior</h3>
<p dir="auto">Submitting with only the first file field set in the browser,<br>
one would expect to find :</p>
<ul dir="auto">
<li>the content of both file fields in the same object ;</li>
<li>the content of normal text input fields in a separate objects ;</li>
</ul>
<p dir="auto">So something along the lines of</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ImmutableMultiDict([('normal_field', 'field_value')])
ImmutableMultiDict([('file', &lt;FileStorage: 'tmp-rg1.xpi' ('application/x-xpinstall')&gt;), 
                    ('secondfile', &lt;FileStorage: '' ('...')&gt;)
                   ])"><pre class="notranslate"><code class="notranslate">ImmutableMultiDict([('normal_field', 'field_value')])
ImmutableMultiDict([('file', &lt;FileStorage: 'tmp-rg1.xpi' ('application/x-xpinstall')&gt;), 
                    ('secondfile', &lt;FileStorage: '' ('...')&gt;)
                   ])
</code></pre></div>
<h3 dir="auto">Actual Behavior</h3>
<p dir="auto">Submitting with only one file (the first field) set in the browser gives:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ImmutableMultiDict([('normal_field', 'field_value'), ('secondfile', '')])
ImmutableMultiDict([('file', &lt;FileStorage: 'tmp-rg1.xpi' ('application/x-xpinstall')&gt;)])"><pre class="notranslate"><code class="notranslate">ImmutableMultiDict([('normal_field', 'field_value'), ('secondfile', '')])
ImmutableMultiDict([('file', &lt;FileStorage: 'tmp-rg1.xpi' ('application/x-xpinstall')&gt;)])
</code></pre></div>
<p dir="auto">The first is the form's field, the second the actual files uploaded. I see no way to distinguish between an empty text field and a non-uploaded file from the <code class="notranslate">request</code> object.<br>
Is this behavior intended ?</p>