@@ -219,6 +219,7 @@ Amplify.configure(outputs);
219219
220220This code sets up a React app to upload an image to an S3 bucket and then use Amazon Rekognition to recognize the text in the uploaded image.
221221
222+ <InlineFilter filters = { [" react" , " javascript" , " nextjs" , " react-native" ]} >
222223``` ts title="App.tsx"
223224import { type ChangeEvent , useState } from " react" ;
224225import { generateClient } from " aws-amplify/api" ;
@@ -282,3 +283,71 @@ function App() {
282283
283284export default App ;
284285```
286+ </InlineFilter >
287+ <InlineFilter filters = { [" angular" ]} >
288+ ``` ts title="app.component.ts"
289+ import { Component } from ' @angular/core' ;
290+ import { generateClient } from ' aws-amplify/api' ;
291+ import { uploadData } from ' aws-amplify/storage' ;
292+ import { Schema } from ' ../../../amplify/data/resource' ;
293+ import { CommonModule } from ' @angular/common' ;
294+
295+ // Generating the client
296+ const client = generateClient <Schema >();
297+
298+ type IdentifyTextReturnType = Schema [' identifyText' ][' returnType' ];
299+
300+ @Component ({
301+ selector: ' app-text-recognition' ,
302+ standalone: true ,
303+ imports: [CommonModule ],
304+ template: `
305+ <div>
306+ <h1>Amazon Rekognition Text Recognition</h1>
307+ <div>
308+ <input type="file" (change)="handleTranslate($event)" />
309+ <button (click)="recognizeText()">Recognize Text</button>
310+ <div>
311+ <h3>Recognized Text:</h3>
312+ {{ textData }}
313+ </div>
314+ </div>
315+ </div>
316+ ` ,
317+ })
318+ export class TodosComponent {
319+ // Component properties instead of React state
320+ path: string = ' ' ;
321+ textData? : IdentifyTextReturnType ;
322+
323+ // Function to handle file upload to S3 bucket
324+ async handleTranslate(event : Event ) {
325+ const target = event .target as HTMLInputElement ;
326+ if (target .files && target .files .length > 0 ) {
327+ const file = target .files [0 ];
328+ const s3Path = ' public/' + file .name ;
329+
330+ try {
331+ await uploadData ({
332+ path: s3Path ,
333+ data: file ,
334+ });
335+
336+ this .path = s3Path ;
337+ } catch (error ) {
338+ console .error (error );
339+ }
340+ }
341+ }
342+
343+ // Function to recognize text from the uploaded image
344+ async recognizeText() {
345+ // Identifying text in the uploaded image
346+ const { data } = await client .queries .identifyText ({
347+ path: this .path , // File name
348+ });
349+ this .textData = data ;
350+ }
351+ }
352+ ```
353+ </InlineFilter >
0 commit comments