Get file size from multipart form upload Content-Length header

后端 未结 2 1513
星月不相逢
星月不相逢 2020-12-16 15:36

So, I\'m uploading a file, and then downloading it... but the Content-Length in the upload headers do not match the file size. I\'m guessing there is some other data involve

相关标签:
2条回答
  • 2020-12-16 16:27

    I think that each section of the multipart/form-data request counts toward the overall size of the main Content-Length header.

    Found this as a reference: http://chxo.com/be2/20050724_93bf.html

    So, perhaps after your headers, you might have:

    ----WebKitFormBoundaryeoFyqD4zr6smwYDG
    
    Content-Disposition: form-data; name="file"; filename="testfile-downloaded.zip"; size=<file size could be here>
    Content-Length: <file size could also be here>
    <some other content headers>
    
    <file data>
    
    ----WebKitFormBoundaryeoFyqD4zr6smwYDG
    

    All of which would count toward the Content-Length size.

    EDIT

    Just realized I didn't answer your question. Not sure how to pull out the file size from the file section of the request. Sorry!

    0 讨论(0)
  • 2020-12-16 16:29

    The data you received is always bigger than you file. Just scan the "boundary" value for the starting and ending of the file.

    The reference: How does HTTP file upload work?

    0 讨论(0)
提交回复
热议问题