get_file_metadata
Returns stored metadata and integrity data for an application file.
get_file_metadata(std::string filename) returns blaze::file_metadata for a
stored application file.
Function variants
blaze::file_metadata get_file_metadata(std::string filename);
blaze::file_metadata get_file_metadata(std::string filename, std::error_code& ec) noexcept;
void async_get_file_metadata(std::string filename, std::function<void(std::error_code, blaze::file_metadata)> callback);
blaze::coro::awaitable_result<blaze::file_metadata> co_get_file_metadata(std::string filename);Status vs error
file_metadata.status is the API result. std::error_code and
std::system_error are used for transport/runtime failures only.
Parameters
Prop
Type
Result
struct file_metadata {
std::string checksum;
uint64_t size;
uint32_t transfer_count;
std::chrono::seconds last_transferred_at;
blaze::status status;
bool good() const noexcept;
};Prop
Type
file_metadata.good() is equivalent to status == blaze::status::ok.
Checking returned fields
Missing fields are returned as default values. If
result.status != blaze::status::ok, treat metadata fields as optional in
practice and check them explicitly.
| Field | Practical check |
|---|---|
result.checksum | result.checksum.empty() |
result.size | Check result.status == blaze::status::ok before relying on it. 0 is valid on success for an empty file. |
result.transfer_count | Check result.status == blaze::status::ok before relying on it. 0 is also valid on success. |
result.last_transferred_at | result.last_transferred_at.count() == 0 means no transfer timestamp was provided. |
Behavior notes
- Call
get_file_metadataonly after successfulconnectandinitialize. - This operation does not require an authorized license or account context.
checksumdescribes the whole stored file, not a transfer range.last_transferred_atis populated only when the server has a successful transfer timestamp for this file.
Example
Compilation note
Synchronous and Asynchronous examples compile in the same form from C++14
to C++26.
#include "blazeauth/api/api.hpp"
#include <iostream>
#include <string>
#include <system_error>
void print_error_code(const std::string& context, const std::error_code& ec) {
std::cout << context << ": " << ec.message() << " ("
<< ec.value() << " : " << ec.category().name() << ")\n";
}
std::string read_line(const std::string& label) {
std::string value;
std::cout << label << ": ";
std::getline(std::cin, value);
return value;
}
void print_status(const std::string& context, blaze::status status) {
std::cout << context << ": "
<< static_cast<unsigned int>(status)
<< " (" << blaze::to_string(status) << ")\n";
}
int main() {
const std::string websocket_api_key = read_line("Websocket API key");
const std::string client_id = read_line("Client ID");
const std::string filename = read_line("Filename");
blaze::session session;
try {
const blaze::api_server server = session.connect();
std::cout << "Connected to server location: " << server.location << '\n';
const blaze::application app = session.initialize(websocket_api_key, client_id);
if (!app.good()) {
print_status("Initialize returned status", app.status);
return 1;
}
const blaze::file_metadata result = session.get_file_metadata(filename);
if (!result.good()) {
print_status("Get-file-metadata returned status", result.status);
return 1;
}
std::cout << "Checksum: " << result.checksum << '\n';
std::cout << "Size: " << result.size << " bytes\n";
std::cout << "Transfer count: " << result.transfer_count << '\n';
if (result.last_transferred_at.count() != 0) {
std::cout << "Last transferred at (unix): " << result.last_transferred_at.count() << '\n';
} else {
std::cout << "Last transferred at: never\n";
}
session.shutdown();
} catch (const std::system_error& e) {
print_error_code("Get-file-metadata failed", e.code());
return 1;
}
return 0;
}#include "blazeauth/api/api.hpp"
#include <future>
#include <iostream>
#include <string>
#include <system_error>
void print_error_code(const std::string& context, const std::error_code& ec) {
std::cout << context << ": " << ec.message() << " ("
<< ec.value() << " : " << ec.category().name() << ")\n";
}
std::string read_line(const std::string& label) {
std::string value;
std::cout << label << ": ";
std::getline(std::cin, value);
return value;
}
void print_status(const std::string& context, blaze::status status) {
std::cout << context << ": "
<< static_cast<unsigned int>(status)
<< " (" << blaze::to_string(status) << ")\n";
}
int main() {
const std::string websocket_api_key = read_line("Websocket API key");
const std::string client_id = read_line("Client ID");
const std::string filename = read_line("Filename");
blaze::session session;
std::promise<int> completion;
std::future<int> result = completion.get_future();
session.async_connect(
[&session, &completion, websocket_api_key, client_id, filename](std::error_code connect_ec, blaze::api_server server) {
if (connect_ec) {
print_error_code("Connect failed", connect_ec);
completion.set_value(1);
return;
}
std::cout << "Connected to server location: " << server.location << '\n';
session.async_initialize(websocket_api_key, client_id,
[&session, &completion, filename](std::error_code init_ec, blaze::application app) {
if (init_ec) {
print_error_code("Initialize failed", init_ec);
completion.set_value(1);
return;
}
if (!app.good()) {
print_status("Initialize returned status", app.status);
completion.set_value(1);
return;
}
session.async_get_file_metadata(
filename,
[&session, &completion](std::error_code metadata_ec, blaze::file_metadata result) {
if (metadata_ec) {
print_error_code("Get-file-metadata failed", metadata_ec);
completion.set_value(1);
return;
}
if (!result.good()) {
print_status("Get-file-metadata returned status", result.status);
completion.set_value(1);
return;
}
std::cout << "Checksum: " << result.checksum << '\n';
std::cout << "Size: " << result.size << " bytes\n";
std::cout << "Transfer count: " << result.transfer_count << '\n';
if (result.last_transferred_at.count() != 0) {
std::cout << "Last transferred at (unix): " << result.last_transferred_at.count() << '\n';
} else {
std::cout << "Last transferred at: never\n";
}
session.async_shutdown([&completion](std::error_code shutdown_ec) {
if (shutdown_ec) {
print_error_code("Shutdown failed", shutdown_ec);
completion.set_value(1);
return;
}
completion.set_value(0);
});
});
});
});
return result.get();
}Project must be built with C++20 support and with coroutine support available both in the language mode and in the standard library implementation for this example to compile correctly.
#include "blazeauth/api/api.hpp"
#include <future>
#include <iostream>
#include <string>
#include <system_error>
void print_error_code(const std::string& context, const std::error_code& ec) {
std::cout << context << ": " << ec.message() << " ("
<< ec.value() << " : " << ec.category().name() << ")\n";
}
std::string read_line(const std::string& label) {
std::string value;
std::cout << label << ": ";
std::getline(std::cin, value);
return value;
}
#if BLAZEAUTH_HAS_COROUTINES
blaze::coro::task<std::error_code> run_example(
blaze::session& session,
const std::string& websocket_api_key,
const std::string& client_id,
const std::string& filename
) {
const auto [connect_ec, server] = co_await session.co_connect();
if (connect_ec) {
co_return connect_ec;
}
std::cout << "Connected to server location: " << server.location << '\n';
const auto [init_ec, app] = co_await session.co_initialize(websocket_api_key, client_id);
if (init_ec) {
co_return init_ec;
}
if (!app.good()) {
co_return blaze::make_error_code(app.status);
}
const auto [metadata_ec, result] = co_await session.co_get_file_metadata(filename);
if (metadata_ec) {
co_return metadata_ec;
}
if (!result.good()) {
co_return blaze::make_error_code(result.status);
}
std::cout << "Checksum: " << result.checksum << '\n';
std::cout << "Size: " << result.size << " bytes\n";
std::cout << "Transfer count: " << result.transfer_count << '\n';
if (result.last_transferred_at.count() != 0) {
std::cout << "Last transferred at (unix): " << result.last_transferred_at.count() << '\n';
} else {
std::cout << "Last transferred at: never\n";
}
const auto [shutdown_ec] = co_await session.co_shutdown();
co_return shutdown_ec;
}
int main() {
const std::string websocket_api_key = read_line("Websocket API key");
const std::string client_id = read_line("Client ID");
const std::string filename = read_line("Filename");
blaze::session session;
std::promise<std::error_code> completion;
std::future<std::error_code> result = completion.get_future();
blaze::coro::co_spawn([&session, &completion, websocket_api_key, client_id, filename]() -> blaze::coro::task<void> {
const std::error_code ec = co_await run_example(session, websocket_api_key, client_id, filename);
completion.set_value(ec);
co_return;
}());
const std::error_code ec = result.get();
if (ec) {
print_error_code("Get-file-metadata failed", ec);
return 1;
}
return 0;
}
#else
int main() {
std::cout << "This example requires coroutine support in the Blazeauth library build.\n";
return 0;
}
#endifGet-file-metadata statuses
| Value | Status | Returned when |
|---|---|---|
1 | ok | Metadata was returned successfully. |
6 | internal_server_error | Server failed while reading file metadata. |
300 | file_not_found | File with the provided filename does not exist in the current application. |
301 | file_invalid_name | filename is shorter than 4 characters. |
Connection-level shutdowns
Normal get-file-metadata results are returned in
result.status. The websocket may still be closed by session-level guards:
| Close code | Meaning | When it can happen |
|---|---|---|
4200 | not_initialized | get_file_metadata was called before a successful initialize. |
4201 | rate_limited | Session or IP rate limiting closed the websocket around this operation. |