c2patool Node.js service example
Install and build
Follow these steps:
Install Node.js and npm from https://nodejs.org/en/download.
Clone this repo by entering this command in a terminal window:
git clone https://github.com/contentauth/c2pa_service_example.git
Download the latest version of c2patool for your platform from https://github.com/contentauth/c2patool/releases.
Extract the zip file and put a copy of the
c2patoolexecutable in the root of this repo (
c2pa_service_exampledirectory). NOTE: Depending on your operating system, you may need to take some extra steps to be able to run this file; for example on MacOS you have to follow the instructions to open a Mac app from an unidentified developer.
Open a terminal window and install the required packages. Enter these commands
Start the service by entering this command:
You'll see this in your terminal:
> email@example.com start
> nodemon server.js
[nodemon] to restart at any time, enter `rs`
[nodemon] watching path(s): *.*
[nodemon] watching extensions: js,mjs,json
[nodemon] starting `node server.js`
CAI HTTP server listening on port 8000.
Try the web app
- Open a browser to http://localhost:8000.
- Click the Choose Files button and select one or more JPEG or PNG images in the native file chooser dialog.
The service uploads the selected images, stores them in the `uploads` folder, and then calls the c2patool to add a C2PA manifest to each image.
- Hover over the badge for information about the associated manifest.
- The service returns the full-sized image, not thumbnails.
- Right-click and download an image to view the credentials on https://verify.contentauthenticity.org/.
Overview of the app
The code in
server.js contains all the server-side logic. It defines three routes:
/versiondisplays the version of c2patool being used
/uploaduploads a file, adds a C2PA manifest, and returns a URL.
/, the default route, serves
/uploadroute for each file and then calls the
addGalleryItemfunction to display the returned image on the page.
The data added to the manifest is determined by the
manifest.json file in the root folder. To modify the information added to the file, modify
For more information about c2patool and manifests, see the documentation.