SHARE
TWEET

Untitled

a guest Jul 31st, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     QFile file("/media/1TB/Картинки/RWy6ONzK6oo.jpg");
  2.     if(file.open(QIODevice::ReadOnly))
  3.     {
  4.         QUrl url("http://localhost:8888");
  5.  
  6.         QNetworkRequest request;
  7.         request.setUrl(url);
  8.  
  9.         QHttpMultiPart multipart(QHttpMultiPart::FormDataType);
  10.  
  11.         QHttpPart image;
  12.         image.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("multipart/form-data"));
  13.         image.setHeader(QNetworkRequest::ContentLengthHeader, QVariant(file.size()));
  14.         image.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("name=\"image\";                 
  15.        filename=\"RWy6ONzK6oo.jpg\""));
  16.         image.setBodyDevice(&file);
  17.  
  18.         multipart.append(image);
  19.  
  20.         QNetworkReply *reply = manager->post(request, &multipart);
  21.         connect(reply, &QNetworkReply::finished, &multipart, &QHttpMultiPart::deleteLater);
  22.  
  23.         QEventLoop wait;
  24.         connect(reply, &QNetworkReply::finished, [&](){
  25.             if(reply->error() == QNetworkReply::NoError)
  26.                 qDebug() << reply->readAll();
  27.  
  28.             reply->deleteLater();
  29.             wait.quit();
  30.  
  31.         });
  32.         wait.exec();
  33.     }
  34.     file.close();
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
 
Top