60 boost::regex re(
"^[a-zA-Z0-9_.]*$");
61 if (!boost::regex_match(nameInCatalog.begin(), nameInCatalog.end(), re)) {
62 throw std::runtime_error(
"The filename can only contain characters, "
63 "numbers, underscores and periods");
67 if ((ws.empty() && filePath.empty()) || (!ws.empty() && !filePath.empty())) {
68 throw std::runtime_error(
"Please select a workspace or a file to publish. Not both.");
72 auto catalogInfoService = std::dynamic_pointer_cast<API::ICatalogInfoService>(
76 if (!catalogInfoService)
77 throw std::runtime_error(
"The catalog that you are using does not support "
78 "publishing to the archives.");
81 if (!filePath.empty()) {
82 std::filesystem::path path(filePath);
83 std::string fileName = path.filename().string();
86 if (nameInCatalog.empty()) {
88 g_log.
notice(
"NameInCatalog has not been set. Using filename instead: " + fileName +
".");
92 if (nameInCatalog.empty()) {
94 g_log.
notice(
"NameInCatalog has not been set. Using workspace name instead: " +
workspace->getName() +
".");
102 Mantid::Kernel::ConfigService::Instance().getString(
"defaultsave.directory") +
workspace->getName() +
".nxs";
106 std::ios_base::openmode mode =
isDataFile(filePath) ? std::ios_base::binary : std::ios_base::in;
109 std::ifstream fileStream(filePath.c_str(), mode);
111 if (fileStream.rdstate() & std::ios::failbit)
130 Poco::URI uri(uploadURL);
131 std::string path(uri.getPathAndQuery());
133 Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> certificateHandler =
134 new Poco::Net::AcceptCertificateHandler(
true);
137 const Poco::Net::Context::Ptr context =
138 new Poco::Net::Context(Poco::Net::Context::CLIENT_USE,
"",
"",
"", Poco::Net::Context::VERIFY_NONE);
141 Poco::Net::SSLManager::instance().initializeClient(
nullptr, certificateHandler, context);
142 Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort(), context);
146 Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_PUT, path, Poco::Net::HTTPMessage::HTTP_1_1);
149 request.setChunkedTransferEncoding(
true);
150 std::ostream &os = session.sendRequest(request);
152 Poco::StreamCopier::copyStream(fileContents, os);
155 Poco::Net::HTTPResponse response;
157 std::istream &responseStream = session.receiveResponse(response);
160 Poco::Net::HTTPResponse::HTTPStatus HTTPStatus = response.getStatus();
164 if (!IDSError.empty()) {
174 }
catch (Poco::Net::SSLException &
error) {
175 throw std::runtime_error(
error.displayText());
179 catch (Poco::Exception &) {
189 std::filesystem::path path(filePath);
190 std::string extension = path.extension().string();
191 if (!extension.empty() && extension[0] ==
'.') {
192 extension = extension.substr(1);
194 std::transform(extension.begin(), extension.end(), extension.begin(), tolower);
195 return extension ==
"raw" || extension ==
"nxs";