How to send/receive files of size upto 15MB

  • Hi,

    I am new in qt. I am using QNetworkAccessManager's put method to upload a file to http server. I am able to send files of upto 600KB but bigger files fail to upload. Also i am not sure whether the code that i am using is optimized or not. This is what I am using.

    @bool HTTPClient::sendFile(QString imagePath)
    bool isSuccess = false;
    QIODevice *file = new QFile(imagePath);
    bool isOpened = file->open(QIODevice::ReadOnly);
    QByteArray fileData;
    fileData = file->readAll();

        qDebug("file could not be opened!");
        return false;
        qDebug("file opened successfully!");
        qDebug("size: %d", fileData.size());
        QMessageBox::information(NULL, "File transfer", "File is too big! Choose a file of size <15MB.");
    QUrl requestURI( cleanURL(QString(kROOTURL) + QString(kFILETRANSFER_URL)));
    QNetworkRequest networkRequest = createRequestHeadder(requestURI);
    networkRequest.setRawHeader(kCONTENT_NAME_KEY, kFILE_NAME);
    QNetworkReply *response = NULL;
    mNetworkManager = new NetworkAccessManager(this);

    // Generate data
    mNetworkManager->syncPut(networkRequest, fileData, response);

    if(QNetworkReply::NoError == mNetworkError ||
       kNETWORK_REPLY_SUCCESS == mResponseCode)
        bool ok;
        QVariantMap result = Json::parse(mNetworkResponse, ok).toMap();
            isSuccess = true;

    delete mNetworkManager;
    mNetworkManager = NULL;
    return isSuccess;

    Can some expert plz suggest a better way to upload and download bigger files in Qt?

    qt developer

  • How exactly does it fail?
    Have you tried using "QHttpMultiPart": for sending file?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.