Example #1
0
def upload(_id):
    if request.method == "POST":
        if ("file" not in request.files
            ):  # name the input attribute to 'file' in the frontend script
            return redirect(request.url)

        file = request.files["file"]
        if file.filename == "":
            return redirect(request.url)
        if file and allowed_file(file.filename):
            ext = file.filename.rsplit(".", 1)[1].lower()
            filename = str(datetime.datetime.now().timestamp()) + "." + ext
            file.save(os.path.join(Config.UPLOAD_FOLDER, filename))

            return jsonify(filename), 200

    return jsonify({"message": "Invalid"}), 400
Example #2
0
def upload_page():
    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 an 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_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
            file.save(file_path)
            result = parse_task.delay(file_path)
            return redirect(url_for('upload_page', filename=filename))

    return render_template('upload.html', title='Upload Data', page='upload')
Example #3
0
def upload_file(list_id, task_id):
    # each file is save in a folder named after the corresponding tasks id and list_id
    directory = os.path.join(app.config['UPLOAD_FOLDER'], list_id, task_id)
    if not os.path.exists(directory):
        os.makedirs(directory)

    # Get the name of the uploaded files
    uploaded_files = request.files.getlist('files[]')
    for file in uploaded_files:
        if file and allowed_file(file.filename):
            # sanitize the filename
            filename = secure_filename(file.filename)
            # save uploaded file permanently
            file.save(os.path.join(directory, filename))
            # save reference in database
            db_create_file(task_id, filename)

    # return the updated task
    task = db_get_task(list_id, task_id)
    if task == None:
        json_abort(500, 'Could not upload file')

    return jsonify(task.__dict__)
Example #4
0
def upload_file(list_id, task_id):
    # each file is save in a folder named after the corresponding tasks id and list_id
    # TODO: compute right path
    directory =
    if not os.path.exists(directory):
        os.makedirs(directory)

    # Get the name of the uploaded files
    uploaded_files = request.files.getlist('files[]')
    for file in uploaded_files:
        if file and allowed_file(file.filename):
            # sanitize the filename
            filename = secure_filename(file.filename)
            # TODO: save uploaded file permanently
            # TODO: save reference in database


    # TODO: return the updated task
    task =
    if task == None:
        json_abort(500, 'Could not upload file')

    return jsonify(task.__dict__)