Qt how to upload file in QNetworkAccessManager::post together with http query strings
-
today im sending simple post request like this :
@QUrl params;
QNetworkRequest request;
params.addQueryItem("key","val");
params.addQueryItem("key2","val2");
request.setUrl("www.tst.com/test.php");
QByteArray postArgs;
postArgs = params.encodedQuery();
QEventLoop loop;
QNetworkReply *reply = networkManager->post(request,postArgs);
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec(); @every thing is working great , but now i need to add new parameter as file (image) to upload ogether with http query strings , how can it be done ?
-
You can find a snippet at last but one comment on this "qtcentre thread":http://www.qtcentre.org/threads/17564-file-upload-using-QNetworkRequest-amp-QNetworkAccessManager
-
Also, 4.8 introduces the QHttpMultiPart class to manage multipart/form-data requests.
A recommended reading is http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4 . -
Git clone this git clone https://code.google.com/p/datacod-qt-tools/ or browse the code "Upcoder Source":http://code.google.com/p/datacod-qt-tools/source/browse/. You can find the code for uploading file in uploader.h and uploader.cpp.
Otherwise there is a plugin for this task here. "Tuckdesign Qt":www.tuckdesign.com/sources/Qt.
-
[quote author="raja26" date="1345198648"]Git clone this git clone https://code.google.com/p/datacod-qt-tools/ or browse the code "Upcoder Source":http://code.google.com/p/datacod-qt-tools/source/browse/. You can find the code for uploading file in uploader.h and uploader.cpp.
Otherwise there is a plugin for this task here. "Tuckdesign Qt":www.tuckdesign.com/sources/Qt.[/quote]
This topic is more than a year old. Please don't re-open such old topics just to add some new suggestions. It is more than likely the original poster has his issue long solved.
-
Except this thread is one of the first that shows up in a google search for this topic and I was quite pleased to see the newer and possibly better suggestion along with the original approach. Because of google, there's real value to keeping these things up to date even if they were started a long time ago.
(Edit: spelling)