I'm trying to upload some file to a remote server using some API (Baidu Net Disk) but i keep getting QNetworkReply::UnknownNetworkError
as the error and Unable to write
as the error string.
This only happens when uploading a file greater than 4MBs ..but for small files (~ 1 mb) everything is fine.
I'm using QHttpMultiPart
and QHttpPart
to upload the file.
First off is there some way i can get a more details error message than just Unable to write .
QString formatedMd5;
// fileChunkSize holds the content of the file divided into segments ..each segment is 4mb or less
foreach (auto hash, mFileChuncks) {
if (hash != mFileChuncks.last()) {
formatedMd5.append(QString("\"%1\",").arg(
QCryptographicHash::hash((hash), QCryptographicHash::Md5).toHex()));
} else {
formatedMd5.append(QString("\"%1\"").arg(
QCryptographicHash::hash((hash), QCryptographicHash::Md5).toHex()));
}
}
qDebug() << "formated md5 " << formatedMd5;
QString targetData =
QString("path=/%1&isdir=0&autoinit=1&rtype=3&block_list=[%2]&size=%3")
.arg(remotePath)
.arg(formatedMd5)
.arg(file->size());
qDebug() << " target data is" << targetData;
QNetworkRequest request(QString("http://pan.baidu.com/rest/2.0/xpan/"
"file?method=precreate&access_token=%1")
.arg(access_token));
request.setHeader(QNetworkRequest::ContentTypeHeader,
"application/x-www-form-urlencoded");
request.setRawHeader(QByteArray("X-LC-Session"),
QString("4yj8b1l5kvo9wiww2st6jdjn3").toUtf8());
QNetworkReply *mReply = networkManager->post(request, targetData.toUtf8());
if (mReply) {
connect(mReply, &QNetworkReply::finished, this,
[=]() { this->finished(mReply); });
}
}
This works well when uploading small files, but fails when uploading larger files....please help me!
I tried cross checking the url parameters... This works well with small files, but failed with large files