Answer the question
In order to leave comments, you need to log in
Why do I get a "device not open" error when I send a QTemporaryFile via POST/multipart from QNetworkAccessManager?
First, a temporary file is created, then the content is written (yes, it is necessary through the FS and not memory), then it is sent by
a POST request.
If I do this, I get the error "QIODevice::read (QTemporaryFile, "/tmp/MyApplication.XM3751"): device not open":
QTemporaryFile* tempFile = new QTemporaryFile();
tempFile->open();
QZipWriter zip(tempFile);
...
zip.close();
...
QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
QHttpPart part;
part.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"data\""));
tempFile->open();
part.setBodyDevice(tempFile);
multiPart->append(part);
tempFile->setParent(multiPart);
QNetworkReply* reply = networkAccessManager.post(QNetworkRequest(QUrl("http://ya.ru")), multiPart);
multiPart->setParent(reply);
Answer the question
In order to leave comments, you need to log in
The problem was that QZipWriter closed the temporary file when exiting the function in its destructor.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question