| 62 | // const includeQuote = true; |
| 63 | |
| 64 | async function inspectFile() { |
| 65 | // Construct file data to inspect |
| 66 | const fileTypeConstant = |
| 67 | ['image/jpeg', 'image/bmp', 'image/png', 'image/svg'].indexOf( |
| 68 | mime.getType(filepath) |
| 69 | ) + 1; |
| 70 | const fileBytes = Buffer.from(fs.readFileSync(filepath)).toString('base64'); |
| 71 | const item = { |
| 72 | byteItem: { |
| 73 | type: fileTypeConstant, |
| 74 | data: fileBytes, |
| 75 | }, |
| 76 | }; |
| 77 | |
| 78 | // Construct request |
| 79 | const request = { |
| 80 | parent: `projects/${projectId}/locations/global`, |
| 81 | inspectConfig: { |
| 82 | infoTypes: infoTypes, |
| 83 | customInfoTypes: customInfoTypes, |
| 84 | minLikelihood: minLikelihood, |
| 85 | includeQuote: includeQuote, |
| 86 | limits: { |
| 87 | maxFindingsPerRequest: maxFindings, |
| 88 | }, |
| 89 | }, |
| 90 | item: item, |
| 91 | }; |
| 92 | |
| 93 | // Run request |
| 94 | const [response] = await dlp.inspectContent(request); |
| 95 | const findings = response.result.findings; |
| 96 | if (findings.length > 0) { |
| 97 | console.log('Findings:'); |
| 98 | findings.forEach(finding => { |
| 99 | if (includeQuote) { |
| 100 | console.log(`\tQuote: ${finding.quote}`); |
| 101 | } |
| 102 | console.log(`\tInfo type: ${finding.infoType.name}`); |
| 103 | console.log(`\tLikelihood: ${finding.likelihood}`); |
| 104 | }); |
| 105 | } else { |
| 106 | console.log('No findings.'); |
| 107 | } |
| 108 | } |
| 109 | // [END dlp_inspect_file] |
| 110 | inspectFile(); |
| 111 | } |