Unable to upload file into Flask serverHow do I check whether a file exists without exceptions?How do I copy a file in Python?jQuery Ajax File UploadHow do I list all files of a directory?How to read a file line-by-line into a list?Delete a file or folderGet the data received in a Flask requestFlask POSTs with Trailing SlashHow to upload and display an image in FlaskFlask request.files() is giving an error of BadRequestKeyError when no files are uploaded

Would allowing versatile weapons wielded in two hands to benefit from Dueling be unbalanced?

How to export all graphics from a notebook?

How many stack cables would be needed if we want to stack two 3850 switches

How to identify whether a publisher is genuine or not?

Contour integration with infinite poles

How do my husband and I get over our fear of having another difficult baby?

How can I alter the human reproductive cycle in order to compete on a hostile planet?

Is it mandatory to use contractions in tag questions and the like?

Does AES-ECB with random padding added to each block satisfy IND-CPA?

How to say "respectively" in German when listing (enumerating) things

IEEE 754 square root with Newton-Raphson

How to add the real hostname in the beginning of Linux cli command

Why is Pelosi so opposed to impeaching Trump?

I transpose the source code, you transpose the input!

How to work around players whose backstory goes against the story?

Detail vs. filler

Incomplete iffalse: How to shift a scope in polar coordinate?

Why, even after his imprisonment, do people keep calling Hannibal Lecter "Doctor"?

As a team leader is it appropriate to bring in fundraiser candy?

How to visualize an ordinal variable predicting a continuous outcome?

French license plates

What does it mean by "my days-of-the-week underwear only go to Thursday" in this context?

Fix Ethernet 10/100 PoE cable with 7 out of 8 wires alive

Windows 10 deletes lots of tiny files super slowly. Anything that can be done to speed it up?



Unable to upload file into Flask server


How do I check whether a file exists without exceptions?How do I copy a file in Python?jQuery Ajax File UploadHow do I list all files of a directory?How to read a file line-by-line into a list?Delete a file or folderGet the data received in a Flask requestFlask POSTs with Trailing SlashHow to upload and display an image in FlaskFlask request.files() is giving an error of BadRequestKeyError when no files are uploaded






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















the following code is suppose to upload selected file to local Flask server.
for some unknown reason the request.files is empty after pressing the submit button in the form. I have no clue of why the file path is not sent to the server..



Flask server's code



import os
from flask import Flask, flash, redirect, render_template, request, url_for
from werkzeug.utils import secure_filename
UPLOAD_FOLDER = 'C:UsersuserDesktopuploads'
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def allowed_file(filename):
return '.' in filename and
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/uploader', 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 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.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return render_template('index.html')
return render_template('index.html')


if __name__ == '__main__':
app.secret_key = 'super secret key'
app.debug = True
app.run()
app.run(debug=True)


HTML form code



<form action="http://localhost:5000/uploader" method="POST" enctype="multipart/form-data">
<input type="file" name="file" class="custom-file-container__custom
file__custom-file-input" id="customFile" accept="*" aria-
label="Choose File">
<input type="hidden" name="MAX_FILE_SIZE" value="10485760"/>
<input type="submit" value="Press to upload file!">
</form>


the code goes into the first 'if' condition and stops as if no path was selected..










share|improve this question
































    0















    the following code is suppose to upload selected file to local Flask server.
    for some unknown reason the request.files is empty after pressing the submit button in the form. I have no clue of why the file path is not sent to the server..



    Flask server's code



    import os
    from flask import Flask, flash, redirect, render_template, request, url_for
    from werkzeug.utils import secure_filename
    UPLOAD_FOLDER = 'C:UsersuserDesktopuploads'
    ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
    app = Flask(__name__)
    app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
    def allowed_file(filename):
    return '.' in filename and
    filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
    @app.route('/uploader', 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 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.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
    return render_template('index.html')
    return render_template('index.html')


    if __name__ == '__main__':
    app.secret_key = 'super secret key'
    app.debug = True
    app.run()
    app.run(debug=True)


    HTML form code



    <form action="http://localhost:5000/uploader" method="POST" enctype="multipart/form-data">
    <input type="file" name="file" class="custom-file-container__custom
    file__custom-file-input" id="customFile" accept="*" aria-
    label="Choose File">
    <input type="hidden" name="MAX_FILE_SIZE" value="10485760"/>
    <input type="submit" value="Press to upload file!">
    </form>


    the code goes into the first 'if' condition and stops as if no path was selected..










    share|improve this question




























      0












      0








      0








      the following code is suppose to upload selected file to local Flask server.
      for some unknown reason the request.files is empty after pressing the submit button in the form. I have no clue of why the file path is not sent to the server..



      Flask server's code



      import os
      from flask import Flask, flash, redirect, render_template, request, url_for
      from werkzeug.utils import secure_filename
      UPLOAD_FOLDER = 'C:UsersuserDesktopuploads'
      ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
      app = Flask(__name__)
      app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
      def allowed_file(filename):
      return '.' in filename and
      filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
      @app.route('/uploader', 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 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.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
      return render_template('index.html')
      return render_template('index.html')


      if __name__ == '__main__':
      app.secret_key = 'super secret key'
      app.debug = True
      app.run()
      app.run(debug=True)


      HTML form code



      <form action="http://localhost:5000/uploader" method="POST" enctype="multipart/form-data">
      <input type="file" name="file" class="custom-file-container__custom
      file__custom-file-input" id="customFile" accept="*" aria-
      label="Choose File">
      <input type="hidden" name="MAX_FILE_SIZE" value="10485760"/>
      <input type="submit" value="Press to upload file!">
      </form>


      the code goes into the first 'if' condition and stops as if no path was selected..










      share|improve this question
















      the following code is suppose to upload selected file to local Flask server.
      for some unknown reason the request.files is empty after pressing the submit button in the form. I have no clue of why the file path is not sent to the server..



      Flask server's code



      import os
      from flask import Flask, flash, redirect, render_template, request, url_for
      from werkzeug.utils import secure_filename
      UPLOAD_FOLDER = 'C:UsersuserDesktopuploads'
      ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
      app = Flask(__name__)
      app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
      def allowed_file(filename):
      return '.' in filename and
      filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
      @app.route('/uploader', 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 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.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
      return render_template('index.html')
      return render_template('index.html')


      if __name__ == '__main__':
      app.secret_key = 'super secret key'
      app.debug = True
      app.run()
      app.run(debug=True)


      HTML form code



      <form action="http://localhost:5000/uploader" method="POST" enctype="multipart/form-data">
      <input type="file" name="file" class="custom-file-container__custom
      file__custom-file-input" id="customFile" accept="*" aria-
      label="Choose File">
      <input type="hidden" name="MAX_FILE_SIZE" value="10485760"/>
      <input type="submit" value="Press to upload file!">
      </form>


      the code goes into the first 'if' condition and stops as if no path was selected..







      python html forms post flask






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 28 at 20:25









      Jared Forth

      1,2073 gold badges8 silver badges21 bronze badges




      1,2073 gold badges8 silver badges21 bronze badges










      asked Mar 28 at 19:51









      Edan Ben IvriEdan Ben Ivri

      155 bronze badges




      155 bronze badges

























          0






          active

          oldest

          votes














          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55405823%2funable-to-upload-file-into-flask-server%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55405823%2funable-to-upload-file-into-flask-server%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현