Solved How get image in QtWebApp
-
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
-
Hi,
Check the size of the request and adapt your server configuration accordingly.
-
Size of the request = 51321.
How do I adapt the server? What else should I change besides the .ini file? -
How would I know ? You did not give any information about the web server you are using.
-
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"