Преглед на файлове

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.");
+  }
 }