| 1 | /* |
| 2 | This file is part of KDE. |
| 3 | |
| 4 | SPDX-FileCopyrightText: 2009 Frederik Gladhorn <gladhorn@kde.org> |
| 5 | |
| 6 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 7 | */ |
| 8 | |
| 9 | #ifndef POSTFILEDATA_H |
| 10 | #define POSTFILEDATA_H |
| 11 | |
| 12 | #include <memory> |
| 13 | |
| 14 | #include <QByteArray> |
| 15 | #include <QIODevice> |
| 16 | #include <QNetworkRequest> |
| 17 | |
| 18 | namespace Attica |
| 19 | { |
| 20 | class PostFileDataPrivate; |
| 21 | |
| 22 | class PostFileData |
| 23 | { |
| 24 | public: |
| 25 | /*! |
| 26 | * Prepare a QNetworkRequest and QByteArray for sending a HTTP POST. |
| 27 | * Parameters and files can be added with addArgument() and addFile() |
| 28 | * Do not add anything after calling request or data for the first time. |
| 29 | */ |
| 30 | PostFileData(const QUrl &url); |
| 31 | ~PostFileData(); |
| 32 | |
| 33 | void addArgument(const QString &key, const QString &value); |
| 34 | void addFile(const QString &fileName, QIODevice *file, const QString &mimeType); |
| 35 | void addFile(const QString &fileName, const QByteArray &file, const QString &mimeType, const QString &fieldName = QStringLiteral("localfile" )); |
| 36 | |
| 37 | QNetworkRequest request(); |
| 38 | QByteArray data(); |
| 39 | |
| 40 | private: |
| 41 | void finish(); |
| 42 | QString randomString(int length); |
| 43 | std::unique_ptr<PostFileDataPrivate> d; |
| 44 | Q_DISABLE_COPY(PostFileData) |
| 45 | }; |
| 46 | |
| 47 | } |
| 48 | |
| 49 | #endif // POSTFILEDATA_H |
| 50 | |