Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How get image in QtWebApp
Forum Updated to NodeBB v4.3 + New Features

How get image in QtWebApp

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 343 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mikeeeeee
    wrote on last edited by
    #1

    Hi!
    I'm trying to write an image in json and send it to the server. But the server does not accept a large request. How do I accept a large request?

    void AppCore::slotApiRequest(QByteArray data)
    {
        QNetworkRequest request;
        request.setHeader( QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded" );
        request.setUrl(QUrl(urlServerForRequest));
        request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true); //разрешает перенаправление
        //request.setHeader(QNetworkRequest::ContentTypeHeader,"application/json");
        request.setHeader( QNetworkRequest::ContentTypeHeader, "multipart/form-data" );
        request.setHeader(QNetworkRequest::ContentLengthHeader,QByteArray::number(data.size()));
        qDebug()<<data.size();
        myApiQuery.post(request, data);
    }
     
    void AppCore::addCategory(QString nameCategory, QString fileName)
    {
        fileName = fileName.remove("file:///");
        //qDebug()<<nameCategory<<fileName;
        QImage myImage(fileName);
     
        QByteArray bArray;
        QBuffer buffer(&bArray);
        buffer.open(QIODevice::WriteOnly);
        myImage.save(&buffer, "BMP");
        QString imageString("data:image/bmp;base64,");
        imageString.append(QString::fromLatin1(bArray.toBase64().data()));
        //qDebug()<<imageString;
     
        QJsonObject jObj = QJsonObject{{"nameCategory", nameCategory}, {"image", imageString}};
        //QJsonObject jObj = QJsonObject{{"nameCategory", nameCategory}, {"image", fileName}};
        QJsonDocument doc = QJsonDocument(jObj);
        QByteArray arrayJson;
        QString strJson(doc.toJson(QJsonDocument::Compact));
        arrayJson += strJson;
     
        urlServerForRequest= urlServer + "addCategory";
        slotApiRequest(arrayJson);
    }
    

    It is my .ini file

    [listener]
    ; host=192.168.0.100
    port=8080
    minThreads=4
    maxThreads=100
    cleanupInterval=60000
    readTimeout=60000
    maxRequestSize=10000000
    maxMultiPartSize=10000000
    
    [logging]
    fileName=../logs/HttpSerwerQtWebApp.log
    minLevel=0
    bufferSize=100
    maxSize=1000000
    maxBackups=2
    timestampFormat=dd.MM.yyyy hh:mm:ss.zzz
    msgFormat={timestamp} {typeNr} {type} {thread} {msg}
    ; QT5 supports: msgFormat={timestamp} {typeNr} {type} {thread} {msg}\n  in {file} line {line} function {function}
    
    [docroot]
    path=docroot
    encoding=UTF-8
    maxAge=60000
    cacheTime=60000
    cacheSize=1000000
    maxCachedFileSize=65536
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Check the size of the request and adapt your server configuration accordingly.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mikeeeeee
        wrote on last edited by
        #3

        Size of the request = 51321.
        How do I adapt the server? What else should I change besides the .ini file?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          How would I know ? You did not give any information about the web server you are using.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mikeeeeee
            wrote on last edited by
            #5

            It turned out to be in startup.cpp you need to remember to change the name, then initialization passes and the server works normally.

            /** Name of this application */
            #define APPNAME "HttpSerwerQtWebAppGameTamada"
            
            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved