Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8907661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:58:28+00:00 2026-06-15T02:58:28+00:00

I am trying to use HTML5 <input type=file/> to upload a file to a

  • 0

I am trying to use HTML5 <input type="file"/> to upload a file to a server running Flask.

There is a decent article explaining how to do this. However, it suggests getting the data that’s been sent to the server using:

PHP: $_SERVER['HTTP_X_FILE_NAME']
Rails: request.env['HTTP_X_FILE_NAME']
Django: request.META['HTTP_X_FILE_NAME']

Unfortunately I do not know an equivalent for the above in Flask. Based on my reading I tried:

  1. request.data
  2. request.stream.read()
  3. request.input_stream.read()
  4. request.input_stream.read(
    request.headers.get(‘content-type’, type=int) or 0)

Unfortunately none seemed to work as expected.

I am using Chrome to upload the file with:

var xhr = new XMLHttpRequest();
xhr.open('POST', '/upload/uri', true);
xhr.send(file);

And in Chrome, after I initiate a transfer, under Headers of the Network transfer of this given POST in the Developer Tools the Content-Length is set to exactly the size of the file being uploaded – which suggests that the file is actually being sent.

I would like to know how to access the file being sent in Flask, or alternatively how one might prefer to send HTML5 files to a server.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T02:58:29+00:00Added an answer on June 15, 2026 at 2:58 am

    Have you seen the update to the article you reference? You can use FormData now and avoid having to deal with AJAX uploads differently than browser ones:

    Quoting from the article:

    var form = document.getElementById('form-id');
    var formData = new FormData(form);
    

    This new FormData instance is all you need to pass on the send() call:

    var xhr = new XMLHttpRequest();
    // Add any event handlers here...
    xhr.open('POST', '/upload/path', true);
    xhr.send(formData);
    

    This will send an Ajax request with all the fields of the form on it, not only file inputs. If there were also text areas, text fields, checkboxes or what have you, they’ll be sent too. Any events that you may be listening to will be called, such as onprogress or onreadystatechange.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use the HTML5 file API and jQuery to show the
I'm trying to use jQuery and the HTML5 File API to get data from
I am trying to use JavaScript to upload image to imgur by this example
I'm trying to use HTML5 to validate a number input. I am using jQuery
I am trying to use JTidy (jtidy-r938.jar) to sanitize an input HTML string, but
I'm trying to use HTML5 Constraint Validation in my forms to help users spot
I am trying to use HTML5 data- attributes in my ASP.NET MVC 1 project.
I'm trying to use html5 validation and ajax. The method checkValidity doesn't solve my
I'm trying to use the HTML5 draggable API (though I realize it has its
I am trying to use the HTML5 canvas element to draw some arcs and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.