1515'use strict' ;
1616
1717/**
18- * Sanitize/Screen PDF content using the Model Armor API.
18+ * Sanitize/Screen PDF file content using the Model Armor API.
1919 *
2020 * @param {string } projectId - Google Cloud project ID.
2121 * @param {string } locationId - Google Cloud location.
2222 * @param {string } templateId - The template ID used for sanitization.
23- * @param {string } pdfContentBase64 - Base64-encoded PDF content to sanitize .
23+ * @param {string } pdfContentFilename - Path to a PDF file .
2424 */
25- async function main ( projectId , locationId , templateId , pdfContentBase64 ) {
25+ async function main ( projectId , locationId , templateId , pdfContentFilename ) {
2626 // [START modelarmor_screen_pdf_file]
2727 /**
2828 * TODO(developer): Uncomment these variables before running the sample.
2929 */
3030 // const projectId = process.env.PROJECT_ID || 'your-project-id';
3131 // const locationId = process.env.LOCATION_ID || 'us-central1';
3232 // const templateId = process.env.TEMPLATE_ID || 'template-id';
33- // const pdfContentBase64 = process.env.PDF_CONTENT_BASE64 || 'BASE64_ENCODED_PDF_CONTENT ';
33+ // const pdfContentFilename = 'path/to/file.pdf ';
3434
3535 // Imports the Model Armor library
3636 const modelarmor = require ( '@google-cloud/modelarmor' ) ;
@@ -39,7 +39,11 @@ async function main(projectId, locationId, templateId, pdfContentBase64) {
3939 const ByteItemType =
4040 protos . google . cloud . modelarmor . v1 . ByteDataItem . ByteItemType ;
4141
42- // Instantiates a client
42+ const fs = require ( 'fs' ) ;
43+
44+ const pdfContent = fs . readFileSync ( pdfContentFilename ) ;
45+ const pdfContentBase64 = pdfContent . toString ( 'base64' ) ;
46+
4347 const client = new ModelArmorClient ( {
4448 apiEndpoint : `modelarmor.${ locationId } .rep.googleapis.com` ,
4549 } ) ;
@@ -55,7 +59,7 @@ async function main(projectId, locationId, templateId, pdfContentBase64) {
5559 } ;
5660
5761 const [ response ] = await client . sanitizeUserPrompt ( request ) ;
58- console . log ( 'PDF Sanitization Result:' , response ) ;
62+ console . log ( JSON . stringify ( response , null , 2 ) ) ;
5963 // [END modelarmor_screen_pdf_file]
6064}
6165
0 commit comments