0

I am trying to upload a CSV file using FLASK using this below code and I am trying to save the session of that file so that I can use later.

if request.method=="POST":
    text=request.files['file']
    text_f=secure_filename(text.filename)
    text.save(os.path.join("",text_f))
    path=os.path.abspath(os.path.join("",text_f))
    with open(path) as tickets:
        ticket=pd.read_csv(tickets)
    tic_body=ticket['body']
    #session['tic_body']=tic_body

Below is the HTML Code.

        <input type="file" class="form-control" id="images" name="file" multiple/>


        <input type="submit" class="btn btn-labeled btn-primary" value="stop">

Using this I am trying to upload a file I am receiving the below error.

werkzeug.exceptions.HTTPException.wrap..newcls: 400 Bad Request: KeyError: 'file'

Note: At times ,when I am not using the session I was able to load the file without any error.

Esskay
  • 23
  • 6
  • i am assuming that the html is inside a form tag...then change the request.files to request.form['file'] – iamklaus Sep 10 '18 at 08:09
  • html is inside a form tag, and I have changed request.files to request.form ,still I am getting the same error. – Esskay Sep 17 '18 at 06:38
  • okay..please go through the below link. its much similar to the problem you are facing i guess... https://stackoverflow.com/questions/19898283/folder-files-upload-with-flask – iamklaus Sep 17 '18 at 08:32

0 Answers0