Reading manifest data
- JavaScript
- Python
- Node.js
- C++
- Rust
That JavaScript library is being extensively revised so the APIs used here may change in the near future.
Use c2pa.read
to read manifest data from an asset; if the asset has a C2PA manifest and was processed without errors, the returned c2paReadResult
contains a manifestStore
object with several useful properties:
- manifests: An object containing all the asset's manifests (
Manifest
objects), keyed by UUID. - activeManifest: A pointer to the latest
manifest
in the manifest store. Effectively the "parent" manifest, this is the likely starting point when inspecting an asset's C2PA data. - validationStatus: A list of any validation errors encountered. See Validation for more information.
try {
// Read in image and get a manifest store
const { manifestStore } = await c2pa.read(sampleImage);
console.log('manifestStore', manifestStore);
// Get the active manifest
const activeManifest = manifestStore?.activeManifest;
console.log('activeManifest', activeManifest);
} catch (err) {
console.error('Error reading image:', err);
}
})();
Use the Reader
object to read manifest data from a file or stream and perform validation on the manifest store.
Use the json()
method to return a JSON manifest report; If there are validation errors, the report includes a validation_status
field.
An asset file may contain many manifests in a manifest store. The most recent manifest is identified by the value of the active_manifest
field in the manifests map.
try:
# Create a reader from a file path.
reader = c2pa.Reader.from_file("path/to/media_file.jpg")
# Print the JSON for a manifest.
print("manifest store:", reader.json())
except Exception as err:
print(err)
The Node.js library is being revised. The documentation will be updated as soon as possible with the latest changes.
Use the read_file
function to read C2PA data from the specified file. This function examines the specified asset file for C2PA data and returns a JSON report if it finds any; it throws exceptions on errors. If there are validation errors, the report includes a validation_status
field.
auto json_store = C2pa::read_file("<ASSET_FILE>", "<DATA_DIR>")
Where:
<ASSET_FILE>
- The asset file to read.<DATA_DIR>
- Optional path to data output directory; If provided, the function extracts any binary resources, such as thumbnails, icons, and C2PA data into that directory. These files are referenced by the identifier fields in the manifest store report.
For example:
auto json_store = C2pa::read_file("work/media_file.jpg", "output/data_dir")
Use the Reader
struct to read manifest data from a file or stream.
Reading from a file
Use from_file
to read manifest data from a file:
use c2pa::Reader;
let reader = Reader::from_file("path/to/file.jpg").unwrap();
There is also an asynchronous version of this method, from_stream_async
.
Reading from a stream
Use from_stream
to read manifest data from a stream:
use std::io::Cursor;
use c2pa::Reader;
let mut stream = Cursor::new(include_bytes!("../tests/fixtures/CA.jpg"));
let reader = Reader::from_stream("image/jpeg", stream).unwrap();
println!("{}", reader.json());
There is also an asynchronous version of this method, from_stream_async
.