Note that there are some explanatory texts on larger screens.

plurals
  1. POSend binary file to server using post with Qt
    primarykey
    data
    text
    <p>In Qt I need to send a sqlite file (binary file) up to a website using post. So what I do is that I open the file and try to read the content of it into a QByteArray that I with help of QNetworkRequest can send to the server. I can handle the request as the file is sent to the server but the file is just empty. Am I reading the content of the sqlite file wrong? (I know that the file excist) Can you see anything wrong with my code?</p> <pre><code>QByteArray data; QFile file("database.sqlite"); if (!file.open(QIODevice::ReadWrite)) return; QDataStream in(&amp;file); in.setVersion(QDataStream::Qt_4_6); in &gt;&gt; data ; QString boundary; QByteArray dataToSend; // byte array to be sent in POST boundary="-----------------------------7d935033608e2"; QString body = "\r\n--" + boundary + "\r\n"; body += "Content-Disposition: form-data; name=\"database\"; filename=\"database.sqlite\"\r\n"; body += "Content-Type: application/octet-stream\r\n\r\n"; body += data; body += "\r\n--" + boundary + "--\r\n"; dataToSend = body.toAscii(); QNetworkAccessManager *networkAccessManager = new QNetworkAccessManager(this); QNetworkRequest request(QUrl("http://www.mydomain.com/upload.aspx")); request.setRawHeader("Content-Type","multipart/form-data; boundary=-----------------------------7d935033608e2"); request.setHeader(QNetworkRequest::ContentLengthHeader,dataToSend.size()); connect(networkAccessManager, SIGNAL(finished(QNetworkReply*)),this, SLOT(sendReportToServerReply(QNetworkReply*))); QNetworkReply *reply = networkAccessManager-&gt;post(request,dataToSend); // perform POST request </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload