Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nable to add both a file stream and key-value pairs to the body of the request simultaneously #1788

Open
hexback opened this issue Feb 2, 2024 · 0 comments

Comments

@hexback
Copy link

hexback commented Feb 2, 2024

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";

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant