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::string fileName = Poco::Path(filePath).getFileName();
85 if (nameInCatalog.empty()) {
87 g_log.
notice(
"NameInCatalog has not been set. Using filename instead: " + fileName +
".");
91 if (nameInCatalog.empty()) {
93 g_log.
notice(
"NameInCatalog has not been set. Using workspace name instead: " +
workspace->getName() +
".");
101 Mantid::Kernel::ConfigService::Instance().getString(
"defaultsave.directory") +
workspace->getName() +
".nxs";
105 std::ios_base::openmode mode =
isDataFile(filePath) ? std::ios_base::binary : std::ios_base::in;
108 std::ifstream fileStream(filePath.c_str(), mode);
110 if (fileStream.rdstate() & std::ios::failbit)
129 Poco::URI uri(uploadURL);
130 std::string path(uri.getPathAndQuery());
132 Poco::SharedPtr<Poco::Net::InvalidCertificateHandler> certificateHandler =
133 new Poco::Net::AcceptCertificateHandler(
true);
136 const Poco::Net::Context::Ptr context =
137 new Poco::Net::Context(Poco::Net::Context::CLIENT_USE,
"",
"",
"", Poco::Net::Context::VERIFY_NONE);
140 Poco::Net::SSLManager::instance().initializeClient(
nullptr, certificateHandler, context);
141 Poco::Net::HTTPSClientSession session(uri.getHost(), uri.getPort(), context);
145 Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_PUT, path, Poco::Net::HTTPMessage::HTTP_1_1);
148 request.setChunkedTransferEncoding(
true);
149 std::ostream &os = session.sendRequest(request);
151 Poco::StreamCopier::copyStream(fileContents, os);
154 Poco::Net::HTTPResponse response;
156 std::istream &responseStream = session.receiveResponse(response);
159 Poco::Net::HTTPResponse::HTTPStatus HTTPStatus = response.getStatus();
163 if (!IDSError.empty()) {
173 }
catch (Poco::Net::SSLException &
error) {
174 throw std::runtime_error(
error.displayText());
178 catch (Poco::Exception &) {