Class HttpFile

Synopsis

#include <lib/inc/drogon/MultiPart.h>

class HttpFile

Description

This class represents a uploaded file by a HTTP request.

Methods

HttpFile
fileContentreturn the content of the file.
fileDataReturn the file data.
fileLengthReturn the file length.
getFileNameReturn the file name;.
getMd5Return the md5 string of the file.
saveSave the file to the file system.
saveAsSave the file to file system with a new name.
setFileSet the contents of the file, usually called by the MultiPartParser parser.
setFileNameSet the file name, usually called by the MultiPartParser parser.

Source

Lines 30-89 in lib/inc/drogon/MultiPart.h. Line 31 in lib/inc/drogon/MultiPart.h.

class HttpFile
{
  public:
    HttpFile(std::shared_ptr<HttpFileImpl> &&implPtr);
    /// Return the file name;
    const std::string &getFileName() const;

    /// Set the file name, usually called by the MultiPartParser parser.
    void setFileName(const std::string &filename);

    /// Set the contents of the file, usually called by the MultiPartParser
    /// parser.
    void setFile(const char *data, size_t length);

    /// Save the file to the file system.
    /**
     * The folder saving the file is app().getUploadPath().
     * The full path is app().getUploadPath()+"/"+this->getFileName()
     */
    int save() const;

    /// Save the file to @param path
    /**
     * @param path if 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()
     */
    int save(const std::string &path) const;

    /// Save the file to file system with a new name
    /**
     * @param filename if the parameter isn't prefixed with "/", "./" or "../",
     * the full path is app().getUploadPath()+"/"+filename, otherwise the file
     * is saved as the filename
     */
    int saveAs(const std::string &filename) const;

    /**
     * @brief return the content of the file.
     *
     * @return string_view
     */
    string_view fileContent() const
    {
        return string_view{fileData(), fileLength()};
    }

    /// Return the file length.
    size_t fileLength() const noexcept;

    /// Return the file data.
    const char *fileData() const noexcept;

    /// Return the md5 string of the file
    std::string getMd5() const;

  private:
    std::shared_ptr<HttpFileImpl> implPtr_;
};





Add Discussion as Guest

Log in to DocsForge