yhirose/cpp-httplib

post multipart/form-data errror

xiangxyq opened this issue · 1 comments

hi

Server code as below:
` for (int i = 0; i < req.files.size(); i++) {

      std::string file_name = "file_" + std::to_string(i);
      const auto& file = req.get_file_value(file_name);
      std::cout <<  file_name << " " << file.content.size() << std::endl;

}`

if I post with more than one file, All files except the first file get size is 0. logs as below
image

test code:
`import sys
from json.decoder import JSONDecodeError
from requests import post
from pathlib import Path

def _test(file):
response = post("http://127.0.0.1:8765/test_api", files=file)

try:
return response.json()
except JSONDecodeError:
raise ValueError(f"返回的文本:{response.text}")

if name == 'main':
file = sys.argv[1]
with Path(file).open("rb") as test_file:
__test_file = {"file_0": test_file.read(), "file_1": test_file.read(), "file_2": test_file.read()}
print(_test(__test_file))
`

@xiangxyq your python code looks incorrect...

a.py

from pathlib import Path

with Path('a.py').open("rb") as f:
    s = f.read()
    print(len(s))
    s = f.read()
    print(len(s))
    s = f.read()
    print(len(s))
> python3 a.py
166
0
0