@JonB ..am really sorry i posted the wrong code..
The API has three stages of uploading the files...and the code i initially was the preparation stage... that`s why i used the QNetworkReply *QNetworkAccessManager::post(const QNetworkRequest &request, const QByteArray &data) ..am really sorry about that..
But here the code for uploading the files
// chuckIterator is a QList<QByteArray>::iterator class member variable pointing to member a QList<QByteArray> class member
// Since the api requires to divide any files greater than 4mb into segments of 4mb (depending on the files size)
if (!chuckIterator.hasNext()) {
return;
}
QByteArray data_ = chuckIterator.next();
int partSequence = mFileChuncks.indexOf(data_);
qDebug() << "running part sequence " << partSequence;
QString url = QString("https://d.pcs.baidu.com/rest/2.0/pcs/"
"superfile2?access_token=%1&method=upload&type=tmpfile&"
"path=/%2&uploadid=%3&partseq=%4")
.arg(access_token)
.arg(remotePath)
.arg(mUploadId)
.arg(partSequence);
qDebug() << "Request Url " << url;
auto path = localPath;
QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QFileInfo info(path);
QString fileName = info.fileName();
QHttpPart filePart;
filePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("file/*"));
filePart.setHeader(
QNetworkRequest::ContentDispositionHeader,
QVariant(QString("form-data; "
"name=\"file\";fieldname=\"chapter\";filename=\"%1\"")
.arg(fileName)));
filePart.setHeader(QNetworkRequest::ContentLengthHeader,data_.size());
filePart.setBody(data_);
file->setParent(multiPart);
multiPart->append(filePart);
QNetworkRequest request(url);
QNetworkReply *mReply = networkManager->post(request, multiPart);
if (mReply) {
connect(mReply, &QNetworkReply::finished, this,
[=]() { this->finished(mReply); });
}