File indexing completed on 2024-04-14 14:16:55

0001 /*
0002     This file is part of KDE.
0003 
0004     SPDX-FileCopyrightText: 2009 Frederik Gladhorn <gladhorn@kde.org>
0005 
0006     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007 */
0008 
0009 #ifndef POSTFILEDATA_H
0010 #define POSTFILEDATA_H
0011 
0012 #include <QByteArray>
0013 #include <QIODevice>
0014 #include <QNetworkRequest>
0015 
0016 namespace Attica
0017 {
0018 class PostFileDataPrivate;
0019 
0020 class PostFileData
0021 {
0022 public:
0023     /**
0024      * Prepare a QNetworkRequest and QByteArray for sending a HTTP POST.
0025      * Parameters and files can be added with addArgument() and addFile()
0026      * Do not add anything after calling request or data for the first time.
0027      */
0028     PostFileData(const QUrl &url);
0029     ~PostFileData();
0030 
0031     void addArgument(const QString &key, const QString &value);
0032     void addFile(const QString &fileName, QIODevice *file, const QString &mimeType);
0033     void addFile(const QString &fileName, const QByteArray &file, const QString &mimeType, const QString &fieldName = QStringLiteral("localfile"));
0034 
0035     QNetworkRequest request();
0036     QByteArray data();
0037 
0038 private:
0039     void finish();
0040     QString randomString(int length);
0041     PostFileDataPrivate *d;
0042     Q_DISABLE_COPY(PostFileData)
0043 };
0044 
0045 }
0046 
0047 #endif // POSTFILEDATA_H