Преглед изворни кода

Added rudimentary check whether the file upload was successful.
Right now just the filesize is compared. Checksum would be better.

Andreas Fetzer пре 10 година
родитељ
комит
29c670b2db
1 измењених фајлова са 14 додато и 0 уклоњено
  1. 14 0
      Libs/XNAT/Core/ctkXnatFile.cpp

+ 14 - 0
Libs/XNAT/Core/ctkXnatFile.cpp

@@ -188,4 +188,18 @@ void ctkXnatFile::saveImpl()
   query.append(QString("&%1=%2").arg("inbody", "true"));
 
   this->session()->upload(filename, query);
+  qint64 localFileSize = file.size();
+  QUuid queryId = this->session()->httpHead(this->resourceUri());
+  QMap<QByteArray, QByteArray> header = this->session()->httpHeadSync(queryId);
+  QVariant sizeOnServer = header.value("Content-Length");
+  qint64 remoteFileSize = sizeOnServer.toLongLong();
+
+  // Retrieving the md5 checksum on the server is not always possible
+  // At least we can check whether the file size is the same
+  if (remoteFileSize != localFileSize)
+  {
+    // Remove corrupted file from server
+    this->erase();
+    throw ctkXnatException("Upload failed! An error occurred during file upload.");
+  }
 }