0

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

Moia
  • 2,216
  • 1
  • 12
  • 34
codeClash
  • 1
  • 2
  • As you're using http you could just capture the traffic using Wireshark to see what's going on – Alan Birtles May 04 '23 at 10:15
  • I used wire shark but I get "new fragment ovelaps old data".. – codeClash May 04 '23 at 11:07
  • Did you read the REST API documentation of the service you use about limitations? – vahancho May 04 '23 at 11:08
  • Yes...they require a large file ( > 4mb)to be divided into segments of size 4mbs..then upload those segments one by one....but even though the file is only 3 mbs...it still fails...it only uploads files of <=1 mb! – codeClash May 04 '23 at 12:35

0 Answers0