Sfoglia il codice sorgente

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

Andreas Fetzer 10 anni fa
parent
commit
29c670b2db
1 ha cambiato i file con 14 aggiunte e 0 eliminazioni
  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.");
+  }
 }