title: What is the difference between Flask's send_file and send_from_directory?
body: <p>It is still not clear for me when to use <code>send_file</code> and when <code>send_from_directory</code>.</p>
  
  <p>I have a file in a folder protected. I can access the file from both methods. So perhaps someone has an example that makes clear which function should be used.</p>
  
  <pre><code>@app.route('/sfile/&lt;id&gt;')
  def sfile(id=None):
  
      try:
          return send_file('protected/'+id, attachment_filename='python.jpg')
      except:
          return('')
  
  @app.route('/sdir/&lt;path:filename&gt;')
  def sdir(filename):
      try:
          return send_from_directory(
              os.path.join(app.instance_path, ''),
              filename
          )
      except:
          return ''
  </code></pre>