title: How to save an image locally from flask request?
body: <p>I am getting an image using this HTML template:</p>
  <pre><code>&lt;div class=&quot;ml-container&quot;&gt;
      &lt;form action=&quot;{{ url_for(&quot;predict&quot;)}}&quot; method=&quot;post&quot;&gt;
          &lt;span&gt;Upload your image here&lt;/span&gt;
          &lt;input name=&quot;Select File&quot; type=&quot;file&quot; name=&quot;get_image&quot;&gt;
          &lt;input type=&quot;submit&quot; class=&quot;my-cta-button&quot; value=&quot;Click here to predict caption&quot;&gt; 
      &lt;/form&gt;
   &lt;/div&gt;
  </code></pre>
  <p>I want to save this image in <code>static/file.jpg</code> folder in my directory using Flask. I am using this code to save it.</p>
  <pre><code>@app.route('/predict', methods = ['GET', 'POST'])
  def predict():
      image = request.form.get('get_image')
      image.save('static/file.jpg')
      caption = greedySearch((encode('static/file.jpg').reshape((1, 2048))))
      
      return render_template('index.html', prediction = caption)
  </code></pre>
  <p>But, it's not working and showing this error:</p>
  <pre><code> * Serving Flask app &quot;__main__&quot; (lazy loading)
   * Environment: production
     WARNING: This is a development server. Do not use it in a production deployment.
     Use a production WSGI server instead.
   * Debug mode: off
   * Running on http://127.0.0.1:80/ (Press CTRL+C to quit)
  127.0.0.1 - - [15/May/2022 12:17:14] &quot;GET / HTTP/1.1&quot; 200 -
  [2022-05-15 12:17:20,170] ERROR in app: Exception on /predict [POST]
  Traceback (most recent call last):
    File &quot;C:\Users\Adarsh\anaconda3\lib\site-packages\flask\app.py&quot;, line 2447, in wsgi_app
      response = self.full_dispatch_request()
    File &quot;C:\Users\Adarsh\anaconda3\lib\site-packages\flask\app.py&quot;, line 1952, in full_dispatch_request
      rv = self.handle_user_exception(e)
    File &quot;C:\Users\Adarsh\anaconda3\lib\site-packages\flask\app.py&quot;, line 1821, in handle_user_exception
      reraise(exc_type, exc_value, tb)
    File &quot;C:\Users\Adarsh\anaconda3\lib\site-packages\flask\_compat.py&quot;, line 39, in reraise
      raise value
    File &quot;C:\Users\Adarsh\anaconda3\lib\site-packages\flask\app.py&quot;, line 1950, in full_dispatch_request
      rv = self.dispatch_request()
    File &quot;C:\Users\Adarsh\anaconda3\lib\site-packages\flask\app.py&quot;, line 1936, in dispatch_request
      return self.view_functions[rule.endpoint](**req.view_args)
    File &quot;&lt;ipython-input-5-ac464086eb60&gt;&quot;, line 46, in predict
      image.save('static/file.jpg')
  AttributeError: 'NoneType' object has no attribute 'save'
  127.0.0.1 - - [15/May/2022 12:17:20] &quot;POST /predict HTTP/1.1&quot; 500 -
  </code></pre>
  <p>How do I save that image in <code>static</code> folder?</p>