Hello,
I build a web app with flask. Through a button the user gonna choose a csv file from a desktop and when he clicks to submit a config file gonna run to import that file (the user previously chosen) into ES. So I got a difficult to code that with flask, this is my try
1- This is the user interface: profile.html
{% extends "base.html" %}
{% block content %}
<h1 class="title"> Welcome, {{ name }}! </h1>
<h3>You can choose your file </h3>
<form enctype="multipart/form-data" class="" action="data" method="post">
<input type="file" name="csvfile" value="">
<input type="submit" name="" value="submit">
</form>
{% endblock %}
2- This is a standard config file: file.config
input{
file{
start_position => "beginning"
sincedb_path => "NUL"
codec => plain { charset => "CP1252" }
}
}
filter{
csv {
separator => ";"
convert => {
"longitude" => "float"
"latitude" => "float"
}
}
date { match => [ "time", "dd MMM yy HH:mm:ss" ] }
mutate{ add_field => { "location" => "%{latitude},%{longitude}" } }
}
output{
elasticsearch {
action => "index"
hosts => ["http://localhost:9200/"]
}
}
3- This is the data function : main.py
from flask import Blueprint, render_template, request
import csv
from flask_login import login_required, current_user
from . import db
main = Blueprint('main', __name__)
@main.route('/')
def index():
return render_template('index.html', methods=['GET', 'POST'])
@main.route('/profile')
@login_required
def profile():
return render_template('profile.html', name=current_user.name)
**@main.route('/data', methods=['GET', 'POST'])**
**def data():**
** if request.method == 'POST':**
** f = request.files['csvfile']**
** f.app.config.from_profile('file.config')**
Could anyone tell me how I can implement that with flask please.