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

          How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

          155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

          Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?