0

Here is my app.component.ts.I have imported aws-sdk/client-textract in app.component.ts and
given region of my textract I donot know where to give my access_key and secret_key and also what are parameters to be passed for textract.If any one can solve this please help me .Thank you

import { Component } from '@angular/core';
import * as AWS from "@aws-sdk/client-textract";

const client = new AWS.Textract({ region: "us-east-1"  });

const params = {
   Document: {
   // Bytes: 
   },
  "FeatureTypes": ["FORMS"],
}


@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'newboto';
  cred : any ;
 async callTextract(){
  try {
     const data = await client.analyzeDocument(params);
    
  } catch (error) {
    console.log(error);
    
  }
}


}

1 Answers1

0

After several days of analysis I have found a answer.Here is how the code should be.

import { Component } from '@angular/core';
import * as AWS from "@aws-sdk/client-textract";

//pass your credentials here
const CREDENTIAL = {
  accessKeyId: 'your accesss key',
  secretAccessKey: 'your secret key',
};


const client_textract = new AWS.Textract({ region:"us-east-1" , credentials:CREDENTIAL})


//while passing parameter remove version to avoid metadata error
//you can also convert your image or pdf to bytes 
const params1 = {
   Document: {
    "S3Object": { 
    //"Bytes" : "your file's bytes"
      "Bucket": "testbucket-kr",
      "Name": "medical_claim.pdf",     
   }
 
   },
  "FeatureTypes": ["FORMS"],
}

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'newboto';
  cred : any ;

 async callTextract(){
  try {   
    this.cred = client_textract.detectDocumentText(params1 )
    console.log(this.cred);  
   
  } catch (error) {
    console.log(error);
    
  }
}