qt file uploading, Connection closed error
-
@Stoyan I think this post solves the new object issue
https://stackoverflow.com/questions/23267925/when-to-delete-qnetworkaccessmanager-pointer
// Delete object whose signal triggered this slot. QObject *manager = sender(); manager->deleteLater();
But this doesn't solve the connection error issue
-
@4j1th
Did you addreplay->deleteLater();
What is the result of replay->errorString(); ?
The code you post should work if you create instance of QNetworkAccessManager every time.
Did you left in code this row:QNetworkAccessManager * manager = new QNetworkAccessManager();
Did you call function uploadFiles() from multiple places?
I suspect that you create multiple connection to server and there is a limitation for such activity. -
@4j1th said in qt file uploading, Connection closed error:
@Stoyan Thanks for the replay
I tried you said but it save same file copy multiple times in server and don't return the send post data in order
I think I understand why this happens. Try to move this row
connect(manager, SIGNAL(finished(QNetworkReply*)), SLOT(fileUploadFinished(QNetworkReply*)));
in the constructor, right after this:
manager = new QNetworkAccessManager();
Else it creates multiple connections for one object.
-
@4j1th
Can you put in the beginning of fileUploadFinished, before checking for errors, this code:QByteArray strreplay = replay->readAll(); qDebug() << "Reply: " << strreplay; qDebug() << "Reply error code: " << replay->error();
Maybe there is some informative response to some of the requests before terminating connection.
This is the list with all error codes: QNetworkReply::NetworkError -
@Stoyan thank you for that debugging idea
"uploading : 2017_06_18_00_00_00_26/raw/8/images/mUarFdVu5ZZmiOqFjLoTz4lXn.JPG" Reply: "27" Reply error code: QNetworkReply::NetworkError(NoError) "upload sucessfull 27" "uploading : 2017_06_18_00_00_00_26/raw/8/images/sj0DMlogCTmdoUZEtBk8pph0R.JPG" Reply: "28" Reply error code: QNetworkReply::NetworkError(NoError) "upload sucessfull 28" "uploading : 2017_06_18_00_00_00_26/raw/8/images/0nMaAxIhlJtNxOPHystIFv2EW.JPG" Reply: "29" Reply error code: QNetworkReply::NetworkError(NoError) "upload sucessfull 29" "uploading : 2017_06_18_00_00_00_26/raw/8/images/0t9VhPJKZjIMppyzZBknOpb4Z.JPG" Reply: "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n<html><head>\n<title>408 Request Timeout</title>\n</head><body>\n<h1>Request Timeout</h1>\n<p>Server timeout waiting for the HTTP request from the client.</p>\n<p>Additionally, a 408 Request Timeout\nerror was encountered while trying to use an ErrorDocument to handle the request.</p>\n</body></html>\n" Reply error code: QNetworkReply::NetworkError(UnknownContentError) "Error transferring http://client.mydomain.com/index.php/update/upload_files - server replied: Request Timeout"
-
@4j1th
If error "RemoteHostClosedError" follow the previous error "UnknownContentError", probably the reason is the first error.
You may run the program some more times to collect more data and contact again your service provider with this information.
It is possible to exists some limitation on your account. For example: number of transferred files for a period. Some servers after too many requests for a short time, ask for some type additional identification (captcha for example).And one more thing (not directly connected to the main problem) - you should close and delete the instance of "replay" even when an error occurred.