Parcourir la source

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

Andreas Fetzer il y a 10 ans
Parent
commit
29c670b2db
1 fichiers modifiés avec 14 ajouts et 0 suppressions
  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.");
+  }
 }