Subir archivos

De WikiEducator
Saltar a: navegación, buscar


<form method=post enctype=multipart/form-data>
  <input type=file name=file>
  <input type=submit value=Attach>
</form>
from werkzeug import secure_filename
 
FILE_FOLDER = '...'
 
@app.route('...', methods=['POST'])
def file_attach():
    # Match name from <input type=file name=file>: 'file'.
    filestorage = request.files['file']
    # Do not allow '..' in the filename.
    filename = secure_filename(filestorage.filename)
    dest = os.path.join(FILE_FOLDER, filename)
    filestorage.save(dest)
    return 'Put your response here.'