Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Starting from <strong>bottle-0.12</strong> the <strong><a href="http://bottlepy.org/docs/dev/api.html?highlight=fileupload#bottle.FileUpload" rel="nofollow noreferrer">FileUpload</a></strong> class was implemented with its <strong>upload.save()</strong> functionality.</p> <p>Here is example for the <strong>Bottle-0.12</strong>:</p> <pre><code>import os from bottle import route, request, static_file, run @route('/') def root(): return static_file('test.html', root='.') @route('/upload', method='POST') def do_upload(): category = request.forms.get('category') upload = request.files.get('upload') name, ext = os.path.splitext(upload.filename) if ext not in ('.png', '.jpg', '.jpeg'): return "File extension not allowed." save_path = "/tmp/{category}".format(category=category) if not os.path.exists(save_path): os.makedirs(save_path) file_path = "{path}/{file}".format(path=save_path, file=upload.filename) upload.save(file_path) return "File successfully saved to '{0}'.".format(save_path) if __name__ == '__main__': run(host='localhost', port=8080) </code></pre> <p>Note: <strong>os.path.splitext()</strong> function gives extension in ".&lt;ext&gt;" format, not "&lt;ext&gt;".</p> <ul> <li><p>If you use version previous to <strong>Bottle-0.12</strong>, change:</p> <pre><code>... upload.save(file_path) ... </code></pre></li> </ul> <p>to:</p> <pre><code> ... with open(file_path, 'wb') as open_file: open_file.write(upload.file.read()) ... </code></pre> <ul> <li>Run server;</li> <li>Type "localhost:8080" in your browser.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload