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;
    initNetworkResponse();
    QIODevice *file = new QFile(imagePath);
    bool isOpened = file->open(QIODevice::ReadOnly);
    QByteArray fileData;
    fileData = file->readAll();

    if(!isOpened)
    {
        qDebug("file could not be opened!");
        return false;
    }
    else
    {
        qDebug("file opened successfully!");
        qDebug("size: %d", fileData.size());
    
        if(fileData.size()>kMAX_UPLOAD_FILE_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();
    
        if(ok)
        {
            isSuccess = true;
        }
    }
    

    file->close();
    delete mNetworkManager;
    mNetworkManager = NULL;
    return isSuccess;
    }@

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

    Thanks
    qt developer



  • How exactly does it fail?
    Have you tried using "QHttpMultiPart":http://qt-project.org/doc/qt-4.8/qhttpmultipart.html for sending file?


Log in to reply
 

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