SHARE
TWEET

POST

a guest Jul 31st, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     QFile *file = new QFile("/path/image.jpg");
  2.     file->open(QIODevice::ReadOnly);
  3.  
  4.     QUrl url("http://localhost:8888");
  5.     QNetworkRequest request;
  6.     request.setUrl(url);
  7.  
  8.     QHttpMultiPart *multipart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
  9.  
  10.     QHttpPart image;
  11.     image.setHeader(QNetworkRequest::ContentLengthHeader, QVariant(file->size()));
  12.     image.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("name=\"image\"; filename=\"name.jpg\""));
  13.     image.setBodyDevice(file);
  14.     file->setParent(multipart);
  15.  
  16.     multipart->append(image);
  17.  
  18.     QNetworkAccessManager manager;
  19.     QNetworkReply *reply = manager.post(request, multipart);
  20.     multipart->setParent(reply);
  21.  
  22.     connect(reply, &QNetworkReply::finished, this, &ServerRest::replyTEST);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top