drogon
C++14/17-based HTTP application framework
Loading...
Searching...
No Matches
drogon::HttpFile Class Reference

This class represents a uploaded file by a HTTP request. More...

#include <drogon/MultiPart.h>

Public Member Functions

 HttpFile (std::shared_ptr< HttpFileImpl > &&implPtr) noexcept
const std::string & getFileName () const noexcept
 Return the file name;.
std::string_view getFileExtension () const noexcept
const std::string & getItemName () const noexcept
 Return the name of the item in multiple parts.
FileType getFileType () const noexcept
 Return the type of file.
void setFileName (const std::string &fileName) noexcept
 Set the file name, usually called by the MultiPartParser parser.
void setFile (const char *data, size_t length) noexcept
int save () const noexcept
 Save the file to the file system.
int save (const std::string &path) const noexcept
 Save the file to path.
int saveAs (const std::string &fileName) const noexcept
 Save the file to file system with a new name.
std::string_view fileContent () const noexcept
 return the content of the file.
size_t fileLength () const noexcept
 Return the file length.
drogon::ContentType getContentType () const noexcept
 Return the content-type of the file.
const char * fileData () const noexcept
 return the pointer of the file data.
std::string getMd5 () const noexcept
 Return the md5 string of the file.
const std::string & getContentTransferEncoding () const noexcept
 Return the content transfer encoding of the file.

Detailed Description

This class represents a uploaded file by a HTTP request.

Member Function Documentation

◆ fileContent()

std::string_view drogon::HttpFile::fileContent ( ) const
inlinenoexcept

return the content of the file.

Returns
std::string_view

◆ fileData()

const char * drogon::HttpFile::fileData ( ) const
noexcept

return the pointer of the file data.

Returns
const char*
Note
This function just returns the beginning of the file data in memory. Users mustn't assume that there is an \0 character at the end of the file data even if the type of the file is text. One should get the length of the file by the fileLength() method, or use the fileContent() method.

◆ getFileExtension()

std::string_view drogon::HttpFile::getFileExtension ( ) const
noexcept

Return the file extension; Note: After the HttpFile object is destroyed, do not use this std::string_view object.

◆ save() [1/2]

int drogon::HttpFile::save ( ) const
noexcept

Save the file to the file system.

The folder saving the file is app().getUploadPath(). The full path is app().getUploadPath()+"/"+this->getFileName()

◆ save() [2/2]

int drogon::HttpFile::save ( const std::string & path) const
noexcept

Save the file to path.

Parameters
pathif the parameter is prefixed with "/", "./" or "../", or is "." or "..", the full path is path+"/"+this->getFileName(), otherwise the file is saved as app().getUploadPath()+"/"+path+"/"+this->getFileName()

◆ saveAs()

int drogon::HttpFile::saveAs ( const std::string & fileName) const
noexcept

Save the file to file system with a new name.

Parameters
fileNameif the parameter isn't prefixed with "/", "./" or "../", the full path is app().getUploadPath()+"/"+filename, otherwise the file is saved as the filename

◆ setFile()

void drogon::HttpFile::setFile ( const char * data,
size_t length )
noexcept

Set the contents of the file, usually called by the MultiPartParser parser.


The documentation for this class was generated from the following file: