# FilePart

<a id="filepart"></a>

# FilePart

```cpp
#include <icy/http/form.h>

class FilePart
```

[Defined in src/http/include/icy/http/form.h:236](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/form.h#L236)

> **Inherits:** [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart)

Form part backed by a file on disk.

## List of all members

| Name | Kind | Owner |
|------|------|-------|
| [`FilePart`](#filepart-1) | `function` | Declared here |
| [`FilePart`](#filepart-2) | `function` | Declared here |
| [`FilePart`](#filepart-3) | `function` | Declared here |
| [`~FilePart`](#filepart-4) | `function` | Declared here |
| [`open`](#open-6) | `function` | Declared here |
| [`reset`](#reset-17) | `function` | Declared here |
| [`writeChunk`](#writechunk) | `function` | Declared here |
| [`write`](#write-20) | `function` | Declared here |
| [`write`](#write-21) | `function` | Declared here |
| [`filename`](#filename-2) | `function` | Declared here |
| [`stream`](#stream-10) | `function` | Declared here |
| [`length`](#length-1) | `function` | Declared here |
| [`_path`](#_path-2) | `variable` | Declared here |
| [`_filename`](#_filename-2) | `variable` | Declared here |
| [`_istr`](#_istr) | `variable` | Declared here |
| [`_fileSize`](#_filesize) | `variable` | Declared here |
| [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart-1) | `function` | Inherited from [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart) |
| [`~FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart-2) | `function` | Inherited from [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart) |
| [`reset`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#reset-18) | `function` | Inherited from [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart) |
| [`writeChunk`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#writechunk-1) | `function` | Inherited from [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart) |
| [`write`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#write-22) | `function` | Inherited from [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart) |
| [`write`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#write-23) | `function` | Inherited from [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart) |
| [`headers`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#headers-1) | `function` | Inherited from [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart) |
| [`initialWrite`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#initialwrite) | `function` | Inherited from [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart) |
| [`contentType`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#contenttype-1) | `function` | Inherited from [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart) |
| [`length`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#length-2) | `function` | Inherited from [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart) |
| [`_contentType`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#_contenttype) | `variable` | Inherited from [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart) |
| [`_length`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#_length) | `variable` | Inherited from [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart) |
| [`_headers`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#_headers) | `variable` | Inherited from [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart) |
| [`_initialWrite`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#_initialwrite) | `variable` | Inherited from [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart) |

## Inherited from [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart)

| Kind | Name | Description |
|------|------|-------------|
| `function` | [`FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart-1)  | Creates the [FormPart](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart) with the given MIME content type. |
| `function` | [`~FormPart`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart-2) `virtual` | Destroys the [FormPart](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#formpart). |
| `function` | [`reset`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#reset-18) `virtual` | Resets the internal state and write position to the beginning. Called by [FormWriter](https://auscaster.com/icey/docs/api-reference/icy-http-FormWriter.md#formwriter) when retrying or recalculating content length. |
| `function` | [`writeChunk`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#writechunk-1) `virtual` | Writes the next chunk of data to the [FormWriter](https://auscaster.com/icey/docs/api-reference/icy-http-FormWriter.md#formwriter). |
| `function` | [`write`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#write-22) `virtual` | Writes the entire part data to the [FormWriter](https://auscaster.com/icey/docs/api-reference/icy-http-FormWriter.md#formwriter) in one call. |
| `function` | [`write`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#write-23) `virtual` | Writes the entire part data to an output stream (used for content-length calculation). |
| `function` | [`headers`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#headers-1)  | Returns the extra MIME headers for this part (e.g. Content-Disposition). |
| `function` | [`initialWrite`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#initialwrite) `virtual` `const` | Returns true if this is the first write call since construction or [reset()](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#reset-18). |
| `function` | [`contentType`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#contenttype-1) `const` | Returns the MIME content type for this part. |
| `function` | [`length`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#length-2) `virtual` `const` | Returns the total byte length of the part data. |
| `variable` | [`_contentType`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#_contenttype)  |  |
| `variable` | [`_length`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#_length)  |  |
| `variable` | [`_headers`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#_headers)  |  |
| `variable` | [`_initialWrite`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#_initialwrite)  |  |

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`FilePart`](#filepart-1)  | Creates the [FilePart](#filepart) for the given path. |
|  | [`FilePart`](#filepart-2)  | Creates the [FilePart](#filepart) for the given path and MIME type. |
|  | [`FilePart`](#filepart-3)  | Creates the [FilePart](#filepart) for the given path and MIME type. The given filename is used as part filename (see [filename()](#filename-2)) only. |
|  | [`~FilePart`](#filepart-4) `virtual` | Destroys the [FilePart](#filepart). |
| `void` | [`open`](#open-6) `virtual` | Opens the file for reading. |
| `void` | [`reset`](#reset-17) `virtual` `override` | Resets the file stream to the beginning and clears initial-write state. |
| `bool` | [`writeChunk`](#writechunk) `virtual` `override` | Writes the next chunk of the file to the [FormWriter](https://auscaster.com/icey/docs/api-reference/icy-http-FormWriter.md#formwriter). |
| `void` | [`write`](#write-20) `virtual` `override` | Writes the entire file content to the [FormWriter](https://auscaster.com/icey/docs/api-reference/icy-http-FormWriter.md#formwriter). |
| `void` | [`write`](#write-21) `virtual` `override` | Writes the entire file content to an output stream (used for content-length calculation). |
| `const std::string &` | [`filename`](#filename-2) `const` | Returns the filename component of the file path (not the full path). |
| `std::ifstream &` | [`stream`](#stream-10)  | Returns a reference to the underlying file input stream. |
| `uint64_t` | [`length`](#length-1) `virtual` `const` `override` | Returns the total file size in bytes. |

---

<a id="filepart-1"></a>

### FilePart

```cpp
FilePart(const std::string & path)
```

[Defined in src/http/include/icy/http/form.h:244](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/form.h#L244)

Creates the [FilePart](#filepart) for the given path.

The MIME type is set to application/octet-stream.

Throws an FileException if the file cannot be opened.

---

<a id="filepart-2"></a>

### FilePart

```cpp
FilePart(const std::string & path, const std::string & contentType)
```

[Defined in src/http/include/icy/http/form.h:250](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/form.h#L250)

Creates the [FilePart](#filepart) for the given path and MIME type.

Throws an FileException if the file cannot be opened.

---

<a id="filepart-3"></a>

### FilePart

```cpp
FilePart(const std::string & path, const std::string & filename, const std::string & contentType)
```

[Defined in src/http/include/icy/http/form.h:257](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/form.h#L257)

Creates the [FilePart](#filepart) for the given path and MIME type. The given filename is used as part filename (see [filename()](#filename-2)) only.

Throws an FileException if the file cannot be opened.

---

<a id="filepart-4"></a>

### ~FilePart

`virtual`

```cpp
virtual ~FilePart()
```

[Defined in src/http/include/icy/http/form.h:261](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/form.h#L261)

Destroys the [FilePart](#filepart).

---

<a id="open-6"></a>

### open

`virtual`

```cpp
virtual void open()
```

[Defined in src/http/include/icy/http/form.h:265](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/form.h#L265)

Opens the file for reading.

#### Exceptions

| Exception | Description |
|-----------|-------------|
| `std::runtime_error` | if the file cannot be opened. |

---

<a id="reset-17"></a>

### reset

`virtual` `override`

```cpp
virtual void reset() override
```

[Defined in src/http/include/icy/http/form.h:268](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/form.h#L268)

Resets the file stream to the beginning and clears initial-write state.

#### Reimplements

- [`FormPart::reset`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#reset-18)

---

<a id="writechunk"></a>

### writeChunk

`virtual` `override`

```cpp
virtual bool writeChunk(FormWriter & writer) override
```

[Defined in src/http/include/icy/http/form.h:273](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/form.h#L273)

Writes the next chunk of the file to the [FormWriter](https://auscaster.com/icey/docs/api-reference/icy-http-FormWriter.md#formwriter). 
#### Returns
true if more data remains; false when the file is fully sent.

#### Reimplements

- [`FormPart::writeChunk`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#writechunk-1)

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `writer` | [`FormWriter`](https://auscaster.com/icey/docs/api-reference/icy-http-FormWriter.md#formwriter) & | The [FormWriter](https://auscaster.com/icey/docs/api-reference/icy-http-FormWriter.md#formwriter) to send the chunk through. |

---

<a id="write-20"></a>

### write

`virtual` `override`

```cpp
virtual void write(FormWriter & writer) override
```

[Defined in src/http/include/icy/http/form.h:277](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/form.h#L277)

Writes the entire file content to the [FormWriter](https://auscaster.com/icey/docs/api-reference/icy-http-FormWriter.md#formwriter).

#### Reimplements

- [`FormPart::write`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#write-22)

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `writer` | [`FormWriter`](https://auscaster.com/icey/docs/api-reference/icy-http-FormWriter.md#formwriter) & | The [FormWriter](https://auscaster.com/icey/docs/api-reference/icy-http-FormWriter.md#formwriter) to send data through. |

---

<a id="write-21"></a>

### write

`virtual` `override`

```cpp
virtual void write(std::ostream & ostr) override
```

[Defined in src/http/include/icy/http/form.h:281](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/form.h#L281)

Writes the entire file content to an output stream (used for content-length calculation).

#### Reimplements

- [`FormPart::write`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#write-23)

#### Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| `ostr` | `std::ostream &` | Output stream to write to. |

---

<a id="filename-2"></a>

### filename

`const`

```cpp
const std::string & filename() const
```

[Defined in src/http/include/icy/http/form.h:284](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/form.h#L284)

Returns the filename component of the file path (not the full path).

---

<a id="stream-10"></a>

### stream

```cpp
std::ifstream & stream()
```

[Defined in src/http/include/icy/http/form.h:287](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/form.h#L287)

Returns a reference to the underlying file input stream.

---

<a id="length-1"></a>

### length

`virtual` `const` `override`

```cpp
virtual uint64_t length() const override
```

[Defined in src/http/include/icy/http/form.h:290](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/form.h#L290)

Returns the total file size in bytes.

#### Reimplements

- [`FormPart::length`](https://auscaster.com/icey/docs/api-reference/icy-http-FormPart.md#length-2)

## Protected Attributes

| Return | Name | Description |
|--------|------|-------------|
| `std::string` | [`_path`](#_path-2)  |  |
| `std::string` | [`_filename`](#_filename-2)  |  |
| `std::ifstream` | [`_istr`](#_istr)  |  |
| `uint64_t` | [`_fileSize`](#_filesize)  |  |

---

<a id="_path-2"></a>

### _path

```cpp
std::string _path
```

[Defined in src/http/include/icy/http/form.h:293](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/form.h#L293)

---

<a id="_filename-2"></a>

### _filename

```cpp
std::string _filename
```

[Defined in src/http/include/icy/http/form.h:294](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/form.h#L294)

---

<a id="_istr"></a>

### _istr

```cpp
std::ifstream _istr
```

[Defined in src/http/include/icy/http/form.h:295](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/form.h#L295)

---

<a id="_filesize"></a>

### _fileSize

```cpp
uint64_t _fileSize
```

[Defined in src/http/include/icy/http/form.h:296](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/form.h#L296)
