Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. How to send/receive files of size upto 15MB
Forum Updated to NodeBB v4.3 + New Features

How to send/receive files of size upto 15MB

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    raj.qtdev
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • P Offline
      P Offline
      portoist
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved