#include <form.hpp>
Form part: a field ( text/plain by default) or a file (with a file name, application/octet-stream by default).
Content is in memory or in a file ( fromFile , fromTemporaryFile , large parts read by Multipart ). It is read with open (stream) or with content , which loads a file content in memory on first call: use open for files. Copies of a part share its file.
- Author
- Vincent Lachenal
- Since
- 0.2
◆ Part() [1/3]
| anch::rest::Part::Part |
( |
| ) |
|
Part default constructor: empty field without name ( text/plain ), to be assigned (model members)
◆ Part() [2/3]
| anch::rest::Part::Part |
( |
std::string_view | name, |
|
|
std::string | content ) |
Field Part constructor ( text/plain )
- Parameters
-
| name | the part name |
| content | the content |
◆ Part() [3/3]
| anch::rest::Part::Part |
( |
std::string_view | name, |
|
|
std::string_view | filename, |
|
|
anch::codec::MediaType | mediaType, |
|
|
std::string | content ) |
File Part constructor
- Parameters
-
| name | the part name |
| filename | the file name |
| mediaType | the content media type |
| content | the content |
◆ content()
| std::string_view anch::rest::Part::content |
( |
| ) |
const |
Get content: file content is loaded in memory on first call
- Returns
- the content
- Exceptions
-
| std::runtime_error | when file can not be read |
◆ fromFile()
| Part anch::rest::Part::fromFile |
( |
std::string_view | name, |
|
|
const std::filesystem::path & | path, |
|
|
anch::codec::MediaType | mediaType, |
|
|
std::optional< std::string_view > | filename = std::nullopt ) |
|
static |
Create part from a file: content is read from the file when it is used (the file is not deleted)
- Parameters
-
| name | the part name |
| path | the file path |
| mediaType | the content media type |
| filename | the file name (default: path file name) |
- Returns
- the part
- Exceptions
-
| std::filesystem::filesystem_error | when file size can not be read |
◆ fromTemporaryFile()
| Part anch::rest::Part::fromTemporaryFile |
( |
std::string_view | name, |
|
|
const std::filesystem::path & | path, |
|
|
anch::codec::MediaType | mediaType, |
|
|
std::optional< std::string_view > | filename ) |
|
static |
Create part from a temporary file: the file is deleted with the last part copy
- Parameters
-
| name | the part name |
| path | the file path |
| mediaType | the content media type |
| filename | the file name (empty for a field) |
- Returns
- the part
- Exceptions
-
| std::filesystem::filesystem_error | when file size can not be read |
◆ getFilename()
| std::optional< std::string_view > anch::rest::Part::getFilename |
( |
| ) |
const |
|
noexcept |
Get file name
- Returns
- the file name, empty for fields
◆ getHeaders() [1/2]
Get other part headers
- Returns
- the headers
◆ getHeaders() [2/2]
Get other part headers ( Content-Disposition and Content-Type are given by name, file name and media type)
- Returns
- the headers
◆ getMediaType()
Get content media type
- Returns
- the media type
◆ getName()
| const std::string & anch::rest::Part::getName |
( |
| ) |
const |
|
noexcept |
Get part name
- Returns
- the name
◆ getPath()
| std::optional< std::filesystem::path > anch::rest::Part::getPath |
( |
| ) |
const |
Get content file path
- Returns
- the path, empty for content in memory
◆ isFile()
| bool anch::rest::Part::isFile |
( |
| ) |
const |
|
noexcept |
Check if part is a file (it has a file name)
- Returns
true when part is a file
◆ isInMemory()
| bool anch::rest::Part::isInMemory |
( |
| ) |
const |
|
noexcept |
Check if content is in memory (not in a file)
- Returns
true when content is in memory
◆ open()
| std::unique_ptr< std::istream > anch::rest::Part::open |
( |
| ) |
const |
Open content stream
- Returns
- the content stream
◆ operator==()
| bool anch::rest::Part::operator== |
( |
const Part & | other | ) |
const |
Equality operator: name, file name, media type, headers and content are compared (files are read)
- Parameters
-
- Returns
true when parts are equal
◆ setMediaType()
Set content media type
- Parameters
-
◆ setName()
| void anch::rest::Part::setName |
( |
std::string_view | name | ) |
|
◆ size()
| std::size_t anch::rest::Part::size |
( |
| ) |
const |
|
noexcept |
Get content size
- Returns
- the content size in bytes
The documentation for this class was generated from the following file: