Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to upload a break off file?
Forum Updated to NodeBB v4.3 + New Features

How to upload a break off file?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 733 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.
  • X Offline
    X Offline
    xinghebuluo
    wrote on last edited by
    #1

    I want upload a break off file.
    Steps:

    1. There is a file, size is 10MB.
    2. upload the file with 5MB to server, and close connect.
    3. upload the file from last point(5MB) to server.
      How should I do in step 3?
      Thanks for your help.

    Sorry, I cann't reply this post. I have add my reply in here:
    Yes, When I do this using QHttpMultiPart and QFile, the program cann't stop in the last.
    I don't know why, here is the code and thanks for your reply:

    QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);

    QHttpPart textPart;
    textPart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name="text""));
    textPart.setBody("my text");

    QHttpPart imagePart;
    imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/jpeg"));
    imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name="image""));
    QFile *file = new QFile("image.jpg");
    file->seek(1000);
    file->open(QIODevice::ReadOnly);
    imagePart.setBodyDevice(file);
    file->setParent(multiPart); // we cannot delete the file now, so delete it with the multiPart

    multiPart->append(textPart);
    multiPart->append(imagePart);

    QUrl url("http://my.server.tld");
    QNetworkRequest request(url);

    QNetworkAccessManager manager;
    QNetworkReply *reply = manager.post(request, multiPart);
    multiPart->setParent(reply); // delete the multiPart with the reply
    // here connect signals etc.

    QTimer timer;
    QEventLoop loop;
    QObject::connect(&timer,SIGNAL(timeout()), &loop, SLOT(quit()));
    timer.start(100);

    int updateProgressTimes = 0;
    while(!pReply->isFinished())
    {
    loop.exec(); // in the last, this exec cann't exit, and cpu is 100%
    }

    1 Reply Last reply
    0
    • mrdebugM Offline
      mrdebugM Offline
      mrdebug
      wrote on last edited by
      #2

      It's easy.
      First step: upload with a header. In the header you will explain that it's a new file, size and name.
      Second step: in the header you will explain size and name and in this case it's in append mode.

      Need programmers to hire?
      www.labcsp.com
      www.denisgottardello.it
      GMT+1
      Skype: mrdebug

      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