![]() |
boost::taar::multipart_reader — Incremental reader over a streamed multipart/form-data body.
// In header: <boost/taar/core/multipart.hpp> class multipart_reader { public: // public member functions multipart_reader(body_reader &, std::string); awaitable< std::optional< multipart_part_header > > next_part(); awaitable< std::size_t > read_some(boost::asio::mutable_buffer); awaitable< std::string > read_some(std::size_t = 64 *1024); awaitable< std::string > read_all(std::uint64_t = 16 *1024 *1024); bool part_done() const noexcept; bool done() const noexcept; // private member functions unspecified step(); };
Obtain one through handler::multipart_stream_arg. Call next_part to move to the next part (skipping whatever is left of the current one), then read_some / read_all for its data. Only the current part is buffered, in pieces, so file fields of any size can be consumed with bounded memory.
while (auto part = co_await form.next_part()) { if (part->is_file()) while (!form.part_done()) store(co_await form.read_some()); else fields[part->name] = co_await form.read_all(); }
multipart_reader public member functionsmultipart_reader(body_reader & body, std::string boundary);
awaitable< std::optional< multipart_part_header > > next_part();Advance to the next part. Returns its headers, or
nullopt after the last part. awaitable< std::size_t > read_some(boost::asio::mutable_buffer buffer);Read some of the current part into buffer; 0 once the part is done.
awaitable< std::string > read_some(std::size_t max = 64 *1024);Read some of the current part as a string of at most max bytes; empty once done.
awaitable< std::string > read_all(std::uint64_t limit = 16 *1024 *1024);Read the rest of the current part, bounded by limit.
Throws: |
boost::taar::exception carrying boost::beast::http::error::body_limit once the part exceeds limit bytes, error::invalid_request_format if the body is malformed, or the transport error. |
bool part_done() const noexcept;True when the current part's data has been fully delivered.
bool done() const noexcept;True after the closing boundary.