How to upload a break off file?
-
I want upload a break off file.
Steps:- There is a file, size is 10MB.
- upload the file with 5MB to server, and close connect.
- 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 multiPartmultiPart->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%
} -
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.