Skip to content

Commit 5dc3a6a

Browse files
committed
run example on regula document reader test saas
1 parent 4c9f056 commit 5dc3a6a

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ typings
44
dist
55
.idea
66
/example/portrait.jpg
7-
/example/document-image.jpg.jpg
7+
/example/document-image.jpg
8+
/example/regula.license

example/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Regula Document Reader js client for the browser and node.js example
2+
3+
4+
:bulb: Before you start: if you just want to play with an online demo, visit our [playground](https://api.regulaforensics.com).
5+
6+
Requirements:
7+
- installed nodejs 12 or higher
8+
- installed npm 6 or higher
9+
10+
Verify **Node.js** and **npm** version:
11+
```bash
12+
node --version
13+
> v12.18.3
14+
npm --version
15+
> 6.14.6
16+
```
17+
18+
Cloning example:
19+
```bash
20+
git clone https://github.com/regulaforensics/DocumentReader-web-js-client.git
21+
cd DocumentReader-web-js-client
22+
```
23+
24+
Setup project and download dependencies:
25+
```bash
26+
npm install
27+
npm run build
28+
cd example
29+
npm install
30+
```
31+
32+
### Running with local Regula Document Reader web API installation
33+
34+
Follow [the instructions](https://docs.regulaforensics.com/web/quick-start-guide) to run Regula Document Reader web API.
35+
Assuming you have successfully launched instance, use next line command to run example:
36+
```bash
37+
# from example folder
38+
node .
39+
40+
# If Regula Document Reader web API is running not on localhost, specify host via env variable:
41+
API_BASE_PATH="http://192.168.0.101:8080" node .
42+
```
43+
44+
### Running using Regula Document Reader web API test SaaS
45+
46+
Get your [free trial here](https://mobile.regulaforensics.com/). You should obtain `regula.license` file.
47+
Copy it to **example** folder. You are ready for running!
48+
49+
Execute example:
50+
```bash
51+
# from example folder
52+
API_BASE_PATH="https://test-api.regulaforensics.com" node .
53+
```
54+
55+
### Output
56+
This sample generates next text output:
57+
```text
58+
---------------------------------------------------------------------------
59+
Document Overall Status: not valid
60+
Document Number Visual: U0996738
61+
Document Number MRZ: U0996738
62+
Validity Of Document Number Visual: 1
63+
Validity Of Document Number MRZ: 1
64+
MRZ-Visual values comparison: 1
65+
---------------------------------------------------------------------------
66+
```
67+
Also, it creates [portrait](portrait.jpg) and [document image](document-image.jpg) pictures inside current folder.
68+
Edit [example](./index.js) on your own , and re-run to see your results.

example/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ const {DOCUMENT_NUMBER} = TextFieldType;
1515

1616
(async () => {
1717
let apiBasePath = process.env.API_BASE_PATH || "http://localhost:8080"
18-
const license = process.env.TEST_LICENSE // optional, used here only for smoke test purposes
18+
let license = process.env.TEST_LICENSE // optional, used here only for smoke test purposes
19+
if (fs.existsSync('regula.license')) license = fs.readFileSync('regula.license')
1920

2021
const api = new DocumentReaderApi({basePath: apiBasePath});
21-
api.setLicense(license) // used here only for smoke test purposes, most of clients will attach license on server side
22+
api.setLicense(license)
2223

2324
const raw_image = fs.readFileSync('australia_passport.jpg').buffer
2425

@@ -46,7 +47,7 @@ const {DOCUMENT_NUMBER} = TextFieldType;
4647
const portraitField = response.images.getField(PORTRAIT)
4748
const portraitFromVisual = portraitField.getValue(Source.VISUAL)
4849
fs.appendFileSync('portrait.jpg', Buffer.from(portraitFromVisual));
49-
// waits fix fs.appendFileSync('document-image.jpg', Buffer.from(documentImage));
50+
fs.appendFileSync('document-image.jpg', Buffer.from(documentImage));
5051

5152
console.log("-----------------------------------------------------------------")
5253
console.log(` Document Overall Status: ${docOverallStatus}`)

0 commit comments

Comments
 (0)