title: Save image from canvas in Flask
body: <p>Can anyone help me with saving canvas to my specific Flask folder? I retrieve image with <code>canvas.toDataURL()</code>, but have no idea how to upload it then</p>
  <p>HTML:</p>
  <pre><code>{% block main %}
      &lt;form action=&quot;/draw&quot; method=&quot;post&quot;&gt;
      &lt;canvas id=&quot;canvas&quot; style=&quot;border-style: solid;&quot; width = &quot;400&quot; height = &quot;400&quot; &gt;&lt;/canvas&gt;&lt;hr&gt;
      &lt;button type=&quot;button&quot; id=&quot;startsave&quot;&gt;Save&lt;/button&gt;
  </code></pre>
  <p>JS:</p>
  <pre><code>window.addEventListener('load', () =&gt; {
      document.getElementById('startsave').addEventListener('click', startsave);
  });
  
  function startsave() {
     var ref = canvas.toDataURL(&quot;image/png&quot;);
     var img = document.createElement(&quot;img&quot;);
     img.setAttribute(&quot;src&quot;, ref);
     img.setAttribute(&quot;name&quot;, &quot;image&quot;);
     // TODO
  }
  
  </code></pre>
  <p>Flask:</p>
  <pre><code>@app.route(&quot;/draw&quot;, methods=[&quot;GET&quot;, &quot;POST&quot;])
  @login_required
  def draw():
      if request.method == &quot;GET&quot;:
          return render_template(&quot;/draw.html&quot;)
      else:
       #TODO
  
  </code></pre>