-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpsender.cpp
More file actions
70 lines (51 loc) · 2.75 KB
/
httpsender.cpp
File metadata and controls
70 lines (51 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
This file (c) by : - Martin Hammerchmidt alias Imote
This file is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
You should have received a copy of the license along with this
work. If not, see <http://creativecommons.org/licenses/by-nc-sa/4.0/>.
If you have contributed to this file, add your name to authors list.
*/
#include "httpsender.h"
HttpSender::HttpSender(){}
HttpSender::Status HttpSender::sendFile()
{
/* We include all the file in part of the request */
file = new QFile(pathToFile, this);
if(!file->open(QIODevice::ReadOnly)) return HttpSender::FILE_ERROR;
QHttpPart filePart;
filePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"uplimgFile\"; filename=\"" + file->fileName() + "\""));
filePart.setBodyDevice(file);
/* We include informations about file in other parts */
QHttpPart fileLanguagePart;
fileLanguagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"uplimgFileLanguage\""));
fileLanguagePart.setBody(lang);
QHttpPart fileLanguageHRPart;
fileLanguageHRPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"uplimgFileLanguageHR\""));
fileLanguageHRPart.setBody(langHR.toStdString().c_str());
/* Now we include user informations */
QHttpPart usernamePart;
usernamePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"uplimgUsername\""));
usernamePart.setBody(username.toStdString().c_str());
QHttpPart privateKeyPart;
privateKeyPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"uplimgKey\""));
privateKeyPart.setBody(privateKey.toStdString().c_str());
QHttpPart uplimgVersionPart;
uplimgVersionPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"uplimgVersion\""));
uplimgVersionPart.setBody(uplimgVersion.toStdString().c_str());
container = new QHttpMultiPart(QHttpMultiPart::FormDataType, this);
container->append(filePart);
container->append(privateKeyPart);
container->append(usernamePart);
container->append(fileLanguagePart);
container->append(fileLanguageHRPart);
container->append(uplimgVersionPart);
QNetworkRequest request;
request.setUrl(url);
manager = new QNetworkAccessManager(this);
reply = manager->post(request, container);
QObject::connect(reply, &QNetworkReply::finished, this, &HttpSender::finished);
QObject::connect(reply, &QNetworkReply::uploadProgress, this, &HttpSender::uploadProgress);
QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SIGNAL(error(QNetworkReply::NetworkError)));
return HttpSender::NO_ERROR;
}