RESTful API on Flask. How to upload a directory to a server RESTful API on Flask. How to upload a directory to a server flask flask

RESTful API on Flask. How to upload a directory to a server


Getting flask to accept files is more code than I want to dump into a SO post. Since the problem is so general, I'm going to point you at resources which give you clear instructions on how to solve this problem.

Here is flask's boilerplate documentation on how to upload files: http://flask.pocoo.org/docs/0.12/patterns/fileuploads/

As it does for many problems, flask has its own module for file uploading. You could take a look at flask-uploads.

If you're really set on using curl to upload a bunch of files in a directory, see this SO post for recursively uploading everything in a directory: Uploading all of files in my local directory with curl


As per the solution provided by @melchoir55 I was able to build a flask api which is able to read a single file at a time. Here, for my requirement I need to upload all files existing in a directory on to a server. What is the way to do so.

@app.route('/', methods=['GET', 'POST'])def upload_file():    if request.method == 'POST':        # check if the post request has the file part        if 'file' not in request.files:            flash('No file part')            return redirect(request.url)        file = request.files['file']        # if user does not select file, browser also        # submit a empty part without filename        if file.filename == '':            flash('No selected file')            return redirect(request.url)        if file and allowed_file(file.filename):            filename = secure_filename(file.filename)            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))            return redirect(url_for('runDocumentManager',input_path=filename))    return '''    <!doctype html>    <title>Upload new File</title>    <h1>Upload new File</h1>    <form method=post enctype=multipart/form-data>      <p><input type=file name=file>         <input type=submit value=Upload>    </form>    '''   

This is the code for uploading file to the flask api server. Here I need to upload all files in a directory in a single go. How should I do it.