Description
The C++ REST SDK does not provide a direct interface for creating multipart form data. I am unable to add both a file stream and key-value pairs to the body of the request simultaneously.
`http_client client(U("http://example.com"));
// 打开要上传的文件流
concurrency::streams::istream fileStream = concurrency::streams::file_stream<uint8_t>::open_istream(U("path/to/file.txt")).get();
// 创建HTTP请求
http_request request(methods::PUT);
request.set_body(fileStream, U("text/plain")); // 设置请求体为文件流,并指定内容类型`
data << "--" << boundary << "\r\n"; data << "Content-Disposition: form-data; name=\"key\"\r\n\r\n" << pixkey << "\r\n"; data << "--" << boundary << "\r\nContent-Disposition: form-data; name=\"callback\"\r\n\r\n" << value << "\r\n"; data << "--" << boundary << "\r\nContent-Disposition: form-data; name=\"policy\"\r\n\r\n" << fdata.policy << "\r\n"; data << "--" << boundary << "\r\nContent-Disposition: form-data; name=\"Signature\"\r\n\r\n" << fdata.Signature << "\r\n"; data << "--" << boundary << "\r\nContent-Disposition: form-data; name=\"OSSAccessKeyId\"\r\n\r\n" << fdata.OSSAccessKeyId << "\r\n"; m_request.set_body(p.second, "multipart/form-data; boundary=" + boundary );
I would like to use both of the above methods to populate the body simultaneously. I want to retrieve the file using a stream instead of converting it into a string and placing it in a key-value pair. How can I put the stream data into a key-value pair?read_entire_file(strm.first)
is the std::string of file.
data << "--" << boundary << "Content-Type: application/octet-stream\r\n\r\n" << read_entire_file(strm.first) << "\r\n\r\n";
Activity