Fix a bug with multipart and return parsing
This commit is contained in:
parent
990bcd5ad9
commit
afbe278155
@ -12,7 +12,7 @@ void ioutils::postMultipart(QUrl target,
|
|||||||
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback) {
|
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback) {
|
||||||
QNetworkRequest req(target);
|
QNetworkRequest req(target);
|
||||||
for (auto header : headers) {
|
for (auto header : headers) {
|
||||||
req.setRawHeader(header.first.toUtf8(), header.second.toUtf8());
|
if (header.first.toLower() != "content-type") req.setRawHeader(header.first.toUtf8(), header.second.toUtf8());
|
||||||
}
|
}
|
||||||
QNetworkReply *reply = networkManager.post(req, body);
|
QNetworkReply *reply = networkManager.post(req, body);
|
||||||
QObject::connect(reply, &QNetworkReply::finished, [reply, callback] {
|
QObject::connect(reply, &QNetworkReply::finished, [reply, callback] {
|
||||||
|
@ -182,12 +182,6 @@ QString parsePathspec(QJsonDocument &response, QString &pathspec) {
|
|||||||
return QString::fromUtf8(response.toJson());
|
return QString::fromUtf8(response.toJson());
|
||||||
}
|
}
|
||||||
QJsonValue val = o[fields.at(0)];
|
QJsonValue val = o[fields.at(0)];
|
||||||
if (val.isUndefined() || val.isNull())
|
|
||||||
return "";
|
|
||||||
else if (val.isString())
|
|
||||||
return val.toString();
|
|
||||||
else if (!val.isObject())
|
|
||||||
return QString::fromUtf8(QJsonDocument::fromVariant(val.toVariant()).toJson());
|
|
||||||
for (int i = 1; i < fields.size(); i++) {
|
for (int i = 1; i < fields.size(); i++) {
|
||||||
if (val.isUndefined() || val.isNull())
|
if (val.isUndefined() || val.isNull())
|
||||||
return "";
|
return "";
|
||||||
@ -325,7 +319,8 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
|||||||
if (str.startsWith("/") && str.endsWith("/")) str = substituteArgs(str, format);
|
if (str.startsWith("/") && str.endsWith("/")) str = substituteArgs(str, format);
|
||||||
part.setRawHeader(headerVal.toLatin1(), str);
|
part.setRawHeader(headerVal.toLatin1(), str);
|
||||||
} else if (headerVal != "body")
|
} else if (headerVal != "body")
|
||||||
cdh += "; " + headerVal + "=\"" + valo[headerVal].toString().replace("\"", "\\\"") + "\"";
|
cdh += "; " + headerVal + "=\""
|
||||||
|
+ substituteArgs(valo[headerVal].toString().toUtf8(), format).replace("\"", "\\\"") + "\"";
|
||||||
}
|
}
|
||||||
part.setHeader(QNetworkRequest::ContentDispositionHeader, cdh);
|
part.setHeader(QNetworkRequest::ContentDispositionHeader, cdh);
|
||||||
multipart->append(part);
|
multipart->append(part);
|
||||||
@ -344,7 +339,7 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
|||||||
[&, buffersToDelete, arraysToDelete](QJsonDocument result, QByteArray data, QNetworkReply *) {
|
[&, buffersToDelete, arraysToDelete](QJsonDocument result, QByteArray data, QNetworkReply *) {
|
||||||
for (auto buffer : buffersToDelete) buffer->deleteLater();
|
for (auto buffer : buffersToDelete) buffer->deleteLater();
|
||||||
for (auto arr : arraysToDelete) delete arr;
|
for (auto arr : arraysToDelete) delete arr;
|
||||||
parseResult(result, data, returnPathspec, name(), urlPrepend, urlPrepend);
|
parseResult(result, data, returnPathspec, name(), urlPrepend, urlAppend);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -365,7 +360,7 @@ void CustomUploader::doUpload(QByteArray imgData, QString format) {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
ioutils::postJson(target, h, data, [&](QJsonDocument result, QByteArray data, QNetworkReply *) {
|
ioutils::postJson(target, h, data, [&](QJsonDocument result, QByteArray data, QNetworkReply *) {
|
||||||
parseResult(result, data, returnPathspec, name(), urlPrepend, urlPrepend);
|
parseResult(result, data, returnPathspec, name(), urlPrepend, urlAppend);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user