HTTP module

FilePart

Form part backed by a file on disk.

FilePart

#include <icy/http/form.h>

Inherits: FormPart

Form part backed by a file on disk.

Public Methods

ReturnNameDescription
FilePartCreates the FilePart for the given path.
FilePartCreates the FilePart for the given path and MIME type.
FilePartCreates the FilePart for the given path and MIME type. The given filename is used as part filename (see filename()) only.
~FilePart virtualDestroys the FilePart.
voidopen virtualOpens the file for reading.
voidreset virtualResets the file stream to the beginning and clears initial-write state.
boolwriteChunk virtualWrites the next chunk of the file to the FormWriter.
voidwrite virtualWrites the entire file content to the FormWriter.
voidwrite virtualWrites the entire file content to an output stream (used for content-length calculation).
const std::string &filename constReturns the filename component of the file path (not the full path).
std::ifstream &streamReturns a reference to the underlying file input stream.
uint64_tlength virtual constReturns the total file size in bytes.

FilePart

FilePart(const std::string & path)

Creates the FilePart for the given path.

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

Throws an FileException if the file cannot be opened.


FilePart

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

Creates the FilePart for the given path and MIME type.

Throws an FileException if the file cannot be opened.


FilePart

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

Creates the FilePart for the given path and MIME type. The given filename is used as part filename (see filename()) only.

Throws an FileException if the file cannot be opened.


~FilePart

virtual

virtual ~FilePart()

Destroys the FilePart.


open

virtual

virtual void open()

Opens the file for reading.

Exceptions

  • std::runtime_error if the file cannot be opened.

reset

virtual

virtual void reset()

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


writeChunk

virtual

virtual bool writeChunk(FormWriter & writer)

Writes the next chunk of the file to the FormWriter.

Parameters

  • writer The FormWriter to send the chunk through.

Returns

true if more data remains; false when the file is fully sent.


write

virtual

virtual void write(FormWriter & writer)

Writes the entire file content to the FormWriter.

Parameters


write

virtual

virtual void write(std::ostream & ostr)

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

Parameters

  • ostr Output stream to write to.

filename

const

const std::string & filename() const

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


stream

std::ifstream & stream()

Returns a reference to the underlying file input stream.


length

virtual const

virtual uint64_t length() const

Returns the total file size in bytes.

Protected Attributes

ReturnNameDescription
std::string_path
std::string_filename
std::ifstream_istr
uint64_t_fileSize

_path

std::string _path

_filename

std::string _filename

_istr

std::ifstream _istr

_fileSize

uint64_t _fileSize