Uploading a file in Multipart form data in Qt5
Unsolved
General and Desktop
-
void product::add(QString photos)
{
QString id=settings.value("id").toString();
qDebug() <<"id"<<id;QString token=settings.value("token").toString(); qDebug() <<"token"<<token; QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); QHttpPart photo; photo.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/*")); photo.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"photo\"")); QFile *file = new QFile(photos); file->open(QIODevice::ReadWrite); photo.setBodyDevice(file); file->setParent(multiPart); multiPart->append(photo); QUrl url("http://localhost:3070/auth/v1/product/Add"); QNetworkRequest request(url); request.setRawHeader("x-access-token","" + token.toUtf8()); QNetworkAccessManager manager; QNetworkReply *reply = manager.post(request, multiPart); multiPart->setParent(reply);
while(!reply->isFinished())
{ qApp->processEvents(); }
}