How to upload screenshot through http multipart ?
Unsolved
General and Desktop
-
I am trying to upload a screenshot to http server. Here is my current code but it doesn't work
QNetworkAccessManager* manager = new QNetworkAccessManager(); QNetworkRequest request; QByteArray data; QBuffer buffer(&data); QScreen* screen = QGuiApplication::primaryScreen(); QPixmap pixmap = screen->grabWindow(0); buffer.open(QIODevice::WriteOnly); pixmap.save(&buffer, "PNG"); QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); QHttpPart imagePart; imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/png")); imagePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"image\"; filename=\"screenshot.png\"")); imagePart.setBodyDevice(&buffer); multiPart->append(imagePart); QObject::connect(manager, &QNetworkAccessManager::finished, &app, [](QNetworkReply* reply){ QString json = reply->readAll(); qDebug() << "Json response" << json; }); request.setUrl(QUrl("Some Upload URL")); manager->post(request, multiPart);
-
Hi,
What exactly does not work ?
What error are you getting ?
Did you check the server's logs to see what happens there ? -
Server is working properly. I am neither getting a response or error but when i remove the append of imagePart, i am getting a response from server.
-
@animeshdhakal said in How to upload screenshot through http multipart ?:
or error
Are you sure? In the code you posted you have no error handling...