KanoopProtocolQt 1.2.3
Qt HTTP operations and MQTT client library
Loading...
Searching...
No Matches
httpupload.h
1#ifndef HTTPUPLOAD_H
2#define HTTPUPLOAD_H
3#include <Kanoop/http/httpoperation.h>
4#include <Kanoop/serialization/iserializabletojson.h>
5
6/** @brief HTTP multipart file upload operation executed asynchronously on a dedicated thread. */
7class LIBKANOOPPROTOCOL_EXPORT HttpUpload : public HttpOperation
8{
9 Q_OBJECT
10public:
11 /** @brief Construct an HTTP upload operation for the given URL and optional filename.
12 * @param url The target URL.
13 * @param filename The path to the file to upload. */
14 HttpUpload(const QString& url, const QString& filename = QString()) :
15 HttpOperation(url, MultipartUpload),
16 _filename(filename) {}
17
18 /** @brief Return the filename to be uploaded.
19 * @return The file path string. */
20 QString filename() const { return _filename; }
21
22 /** @brief Set the filename to be uploaded.
23 * @param value The file path string. */
24 void setFilename(const QString& value) { _filename = value; }
25
26 /** @brief Add a form parameter to the multipart upload.
27 * @param key The parameter name.
28 * @param value The parameter value. */
29 void addParameter(const QString& key, const QString& value);
30
31protected:
32 /** @brief Execute the multipart file upload. */
33 virtual void execute() override;
34
35private:
36 QString _filename;
37 QList<KeyValuePair> _parameters;
38
39 QHttpMultiPart* _multipart = nullptr;
40 QFile* _file = nullptr;
41
42signals:
43 /** @brief Emitted to report upload progress.
44 * @param sent The number of bytes sent so far.
45 * @param total The total number of bytes to send. */
46 void uploadProgress(uint64_t sent, uint64_t total);
47};
48
49#endif // HTTPUPLOAD_H
Base class for HTTP operations executed asynchronously on a dedicated thread.
HTTP multipart file upload operation executed asynchronously on a dedicated thread.
Definition httpupload.h:8
virtual void execute() override
Execute the multipart file upload.
void setFilename(const QString &value)
Set the filename to be uploaded.
Definition httpupload.h:24
void addParameter(const QString &key, const QString &value)
Add a form parameter to the multipart upload.
void uploadProgress(uint64_t sent, uint64_t total)
Emitted to report upload progress.
HttpUpload(const QString &url, const QString &filename=QString())
Construct an HTTP upload operation for the given URL and optional filename.
Definition httpupload.h:14
QString filename() const
Return the filename to be uploaded.
Definition httpupload.h:20