SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    742
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Question multipart/form-data

    Hi

    When uploading a file using HTML, we use the following method in the form tag

    Code:
    multipart/form-data
    I know we use it when uploading file but I want to know what does it do? Why cannot we upload a file without this method?



    Thanks

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Because that's how the HTTP protocol says we do it It's called "multipart" because the HTTP request has "multiple parts" -- one for the main request body, one for the form data, one for each binary object, separated by multipart boundaries.

    RFC 1867: Form-Based File Upload in HTML

    Hypertext Transfer Protocol -- HTTP/1.1

  3. #3
    SitePoint Wizard silver trophybronze trophy
    Join Date
    Jul 2008
    Location
    New York, NY
    Posts
    1,432
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The default encoding type, application/x-www-form-urlencoded, lists field names and values similar to how they appear in the query parameters in a GET request. For instance,
    Code:
    POST /form.php HTTP/1.1
    Host: www.example.com
    
    name=Jane&age=42&skills=html,css
    As you can see, this type of encoding is not useful for uploading files, because files can contain any character.

    With a multipart/form-data encoding the POST request body is split into multiple parts. Each part is delimited by a special identifier string, which makes it possible for the receiving application to detect the end of the uploaded file's content.
    Birnam wood is come to Dunsinane

  5. #5
    SitePoint Guru phantom007's Avatar
    Join Date
    May 2008
    Posts
    742
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Quote Originally Posted by AutisticCuckoo View Post
    The default encoding type, application/x-www-form-urlencoded, lists field names and values similar to how they appear in the query parameters in a GET request. For instance,
    Code:
    POST /form.php HTTP/1.1
    Host: www.example.com
    
    name=Jane&age=42&skills=html,css
    As you can see, this type of encoding is not useful for uploading files, because files can contain any character.

    With a multipart/form-data encoding the POST request body is split into multiple parts. Each part is delimited by a special identifier string, which makes it possible for the receiving application to detect the end of the uploaded file's content.
    Now that is what I call an "answer"


    many thanks AutisticCuckoo, your 2 minute effort helped me understand the concept and saved an hour of mine from reading a 3 page confusing article.


    Thanks again

  6. #6
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad I could help!
    Birnam wood is come to Dunsinane


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •