Skip to content

Commit

Permalink
fix writing file out in multipartformupload endpoint to use binary mo…
Browse files Browse the repository at this point in the history
…de so files are written correctly
  • Loading branch information
nam20485 committed May 2, 2024
1 parent 53fc70f commit a13a690
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions OdbDesignServer/Controllers/FileUploadController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace Odb::App::Server
const auto& contentType = req.get_header_value("Content-Type");
if (contentType != "application/octet-stream")
{
return crow::response(crow::status::BAD_REQUEST, "unsupported content type: this endpoint only accepts 'applicaiton/octet-stream'");
return crow::response(crow::status::BAD_REQUEST, "unsupported content type: this endpoint only accepts 'applicaiton/octet-stream'");
}

return handleOctetStreamUpload(filename, req);
Expand Down Expand Up @@ -164,7 +164,7 @@ namespace Odb::App::Server

// Create a new file with the extracted file name and write file contents to it
const auto tempPath = temp_directory_path() / std::tmpnam(nullptr);

Check warning on line 166 in OdbDesignServer/Controllers/FileUploadController.cpp

View workflow job for this annotation

GitHub Actions / CMake-Multi-Platform-Build (windows-2022, x64-release)

'tmpnam': This function or variable may be unsafe. Consider using tmpnam_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.

Check warning on line 166 in OdbDesignServer/Controllers/FileUploadController.cpp

View workflow job for this annotation

GitHub Actions / CMake-Multi-Platform-Build (macos-12, macos-release)

'tmpnam' is deprecated: This function is provided for compatibility reasons only. Due to security concerns inherent in the design of tmpnam(3), it is highly recommended that you use mkstemp(3) instead. [-Wdeprecated-declarations]
std::ofstream out_file(tempPath);
std::ofstream out_file(tempPath, std::ofstream::binary);
if (!out_file)
{
CROW_LOG_ERROR << " Write to file failed\n";
Expand All @@ -176,7 +176,6 @@ namespace Odb::App::Server
auto safeName = sanitizeFilename(outfile_name);
path finalPath(m_serverApp.args().designsDir());
finalPath /= safeName;
//rename(tempPath, finalPath);
auto ec = fastcopy(tempPath, finalPath, false);

Check warning on line 179 in OdbDesignServer/Controllers/FileUploadController.cpp

View workflow job for this annotation

GitHub Actions / CMake-Multi-Platform-Build (ubuntu-22.04, linux-release)

variable ‘ec’ set but not used [-Wunused-but-set-variable]

Check warning on line 179 in OdbDesignServer/Controllers/FileUploadController.cpp

View workflow job for this annotation

GitHub Actions / CMake-Multi-Platform-Build (macos-12, macos-release)

unused variable 'ec' [-Wunused-variable]

CROW_LOG_INFO << " Contents written to " << outfile_name << '\n';
Expand Down

0 comments on commit a13a690

Please sign in to comment.