Quantcast
Channel: Qt DevNet forums: Qt WebKit
Viewing all articles
Browse latest Browse all 542

[Solved]QNetworkAccessManager Upload Image to WebService

$
0
0
Hello, I try to upload an image with QNetworkAccessManager to webServiceREST, and I have no success. I know he works with Delphi. Tested and confirmed. With Qt I load all the bytes to the server, but the error occurs at the end. what I did wrong in Qt? Application message: starting D:\projetos\Zdemos\qt\rest\Demo1\build-restDemo1-Desktop_Qt_5_2_1_MinGW_32bit-Debug\debug\restDemo1.exe… bytesSent 16384 85848 bytesTotal bytesSent 85848 85848 bytesTotal 299 slotError bytesSent bytesTotal 0 0 statusCodeV. “500” web service error: {“error”: “TsmServerMethodsUnit.updateUploadImagem method not found in the list server method”} Application terminate. Notes: 1-Metode updateUploadImagem not exist in the webservice, is the correct metode UploadImagem I not then inform metode updateUploadImagem name, Qt did THAT? 2)The parameter in webservice is a Stream. 3)In example in delphi, I make execute perfect. code: MainWindow::MainWindow(QWidget *parent) :     QMainWindow(parent),     ui(new Ui::MainWindow) {     ui->setupUi(this);       ui->lineEdit->setText("http://www.mechame.homeip.net:8080/datasnap/rest/DSAdmin/GetPlatformName");       this->manager = new QNetworkAccessManager(this);     QObject::connect(this->manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(finishedSlot(QNetworkReply*)));   } void MainWindow::on_pushButton_3_clicked() {       QString filePath("C:/TEMP/0.jpg");     QUrl url("http://www.mechame.homeip.net:8080/datasnap/rest/TsmServerMethodsUnit/UploadImagem");         QFile *file = new QFile(filePath);     file->open(QIODevice::ReadOnly);       QNetworkRequest request;     request.setUrl(url);     //request.setHeader(QNetworkRequest::ContentTypeHeader,"application/octet-stream"); //Required!     request.setHeader(QNetworkRequest::ContentTypeHeader,"text/plain"); //Required!       QNetworkReply *reply = this->manager->post(request,file->readAll());     file->setParent(reply);       QObject::connect(reply, SIGNAL(uploadProgress(qint64,qint64)), this, SLOT(onUploadProgress(qint64,qint64)));     QObject::connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError)));   } void MainWindow::finishedSlot(QNetworkReply* reply) {       QMessageBox msgBox;       QVariant statusCodeV =reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);     // "200 OK" received?       qDebug()<<"statusCodeV.=="<<statusCodeV.toString();       QByteArray bytes = reply->readAll(); // bytes     const QString string(bytes); // string       ui->textBrowser->setText(string);         if (statusCodeV.toInt()==200)     {         msgBox.setText("Successfull!...");     }     else     {         msgBox.setText("UnSuccessfull!...");     }     msgBox.exec(); }   void MainWindow::slotReadyRead() {     //Q_UNUSED(request); }   void MainWindow::slotSslErrors(QList<QSslError> erros) {     qDebug()<<"slotSslErrors=="<<erros; }   void MainWindow::slotError(QNetworkReply::NetworkError error) {     qDebug()<<"slotError=="<<error; }

Viewing all articles
Browse latest Browse all 542

Trending Articles