Apache benchmark multipart/form-data

前端 未结 1 1536
死守一世寂寞
死守一世寂寞 2021-01-03 17:23

i\'m facing a strange problem with apache benchmark post file.

I need to stress a feature that handles file upload. So, I googled about, and found a post describing

相关标签:
1条回答
  • 2021-01-03 17:46

    I found the answer, and decided to share with you.

    After some struggle with the post file, I decided to create a php script just to output the $_FILES and $_REQUEST variables to see if the file was built correctly. Indeed, apache receive the file perfectly and I could see the file data, and other request params.

    With Rails the same doesn't occur, and after reading the documentation of HTTP 1.1 multipart topic, I realize that the problem was related to the post file format.

    When you built this kind of file, you need to build it in details, and this means include all the special characters like \r and \n in the right place. The multipart does now work with "\n" at all, it needs "dos" line ending "\r\n".

    So the correct post file looks like this (the \r\n is for illustration, but should be there, you know?):

    --boundary_hash\r\n
    Content-Disposition: form-data; name="your_form_field";\r\n
    Content-Type: text/plain\r\n
    \r\n
    your form field data\r\n
    --boundary_hash\r\n
    Content-Disposition: form-data; name="another_field";\r\n
    Content-Type: text/plain\r\n
    \r\n
    another field data\r\n
    --boundary_hash\r\n
    Content-Disposition: form-data; name="filename"; filename="cf_login.png"\r\n
    Content-Type: image/png\r\n
    \r\n
    base64 file content\r\n
    --boundary_hash--\r\n
    

    When you open this file you see this actually:

    --boundary_hash
    Content-Disposition: form-data; name="your_form_field";
    Content-Type: text/plain
    
    your form field data
    --boundary_hash
    Content-Disposition: form-data; name="another_field";
    Content-Type: text/plain
    
    another field data
    --boundary_hash
    Content-Disposition: form-data; name="filename"; filename="cf_login.png"
    Content-Type: image/png
    
    base64 file content
    --boundary_hash--
    

    I hope that helps you.

    Cheers.

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