QNetworkReply发出uploadProgress 0 0,但完成信号延迟发出

时间:2019-03-27 10:42:25

标签: c++ qt qnetworkreply

信号uploadProgress(qint64,qint64)发出0 0,但完成(QNetworkReply *)发出的延迟很长。我认为将文件上传到某个中间缓冲区而不是远程服务器时会发出信号。如何获得真实的上传进度?

Qt 5.12,Windows 7。

QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);

QHttpPart profileIdPart;
profileIdPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"profile_id\""));
profileIdPart.setBody(GlobalsArgs::profileID.toUtf8());
multiPart->append(profileIdPart);

QHttpPart fileTypePart;
fileTypePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"file_type\""));
fileTypePart.setBody(fileT.toUtf8());
multiPart->append(fileTypePart);

fileObj = new QFile(file);
QHttpPart imagePart;
imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"file\"; filename=\"" + fileObj->fileName() +"\""));
imagePart.setHeader(QNetworkRequest::ContentLengthHeader, fileInfo.size());
fileObj->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
imagePart.setBodyDevice(fileObj);
fileObj->setParent(multiPart);
multiPart->append(imagePart);

QUrl url(GlobalsArgs::uploadURL + "/files/");
QByteArray headerRowName;
headerRowName.append(" Bearer " + GlobalsArgs::uploadToken);

QNetworkRequest request(url);
request.setRawHeader("Authorization", headerRowName);
request.setAttribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::AlwaysNetwork);
request.setAttribute(QNetworkRequest::DoNotBufferUploadDataAttribute, true);

manager = new QNetworkAccessManager();
reply = manager->post(request, multiPart);
multiPart->setParent(reply);

0 个答案:

没有答案