How can i send file over http with Qt?
-
Hi,
I have .bin file and i want to upload this file via http i tried following code, but not happened anything.
QFile* file = new QFile("C:/Users/Hp/Desktop/FileTest/2022-12-16 15-09-21.bin"); QHttpMultiPart * multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); QHttpPart filePart; file->open(QIODevice::ReadOnly); filePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/zip")); //or whatever type of your file. filePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"bin\"")); filePart.setHeader(QNetworkRequest::ContentLengthHeader, file->size()); file->setParent(multiPart); filePart.setBodyDevice(file); multiPart->append(filePart); QNetworkAccessManager mgr; QNetworkRequest req(QUrl("some/url")); //req.setRawHeader("Authorization", ("Token <token>")); [[maybe_unused]] QNetworkReply * reply = mgr.post(req, multiPart);Thanks for helps.
-
Hi,
I have .bin file and i want to upload this file via http i tried following code, but not happened anything.
QFile* file = new QFile("C:/Users/Hp/Desktop/FileTest/2022-12-16 15-09-21.bin"); QHttpMultiPart * multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); QHttpPart filePart; file->open(QIODevice::ReadOnly); filePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/zip")); //or whatever type of your file. filePart.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"bin\"")); filePart.setHeader(QNetworkRequest::ContentLengthHeader, file->size()); file->setParent(multiPart); filePart.setBodyDevice(file); multiPart->append(filePart); QNetworkAccessManager mgr; QNetworkRequest req(QUrl("some/url")); //req.setRawHeader("Authorization", ("Token <token>")); [[maybe_unused]] QNetworkReply * reply = mgr.post(req, multiPart);Thanks for helps.
@Yaldiz said in How can i send file over http with Qt?:
but not happened anything.
Did you check what the
replyobject returned had to say? Did you receive theQNetworkAccessManager/QNetworkReply::finishedsignals? What about thefile->open()call just to be sure? Is the Urlhttpand nothttps? -
@Yaldiz said in How can i send file over http with Qt?:
but not happened anything.
Did you check what the
replyobject returned had to say? Did you receive theQNetworkAccessManager/QNetworkReply::finishedsignals? What about thefile->open()call just to be sure? Is the Urlhttpand nothttps?