Hello,
I am creating an open source plugin where i use aws textextract to transform img scan to text,
when i trying to use it the plugin is taking a few secunds and that’s making the app faild, and also i can’t get the text of the scan images.
how i could make that the app will wait until it’s get the text ?
Well, you’ve only got 30 seconds. That’s hard coded.
You probably are looking to use the context.async function provided by the plugin builder. Have you explored that context yet?
thats what i am using, i do an await to get the text then i return the text.
the code dosent take 30 secunds, far maybe 5 not more, so i don’t know why it’s trowing me this error.
Here the code
function(properties, context) {
const aws = require(‘aws-sdk’)
aws.config.update({
accessKeyId: context.accessKeyId,
secretAccessKey: context.secretAccessKey,
region: context.region
});
const extract = new aws.Textract()
var options = {
uri: "https:"+properties.image_to_text,
method: "GET",
encoding: null,
headers: { "Content-type": "application/octet-stream" }
};
const buffer = context.request(options).body;
const text = context.async(async callback => {
try {
const parse = await extract.detectDocumentText({ Document: { Bytes: buffer } }).promise()
return parse.Blocks.filter(b => b.BlockType === 'LINE').map(w => w.Text).join('\n')
} catch (error) {
console.log('error with Textract', error)
}
})
return {imageText: text}
}
Instead of return
Try wrapping your return like this callback(<VALUEtoRETURN>)
in the callback()
Like this ? i tried i still have the same problem
const buffer = context.request(options).body;
context.async(async callback => {
try {
const parse = await extract.detectDocumentText({ Document: { Bytes: buffer } }).promise()
const text = await parse.Blocks.filter(b => b.BlockType === 'LINE').map(w => w.Text).join('\n')
console.log('ouech text',text)
return {imageText: text}
} catch (error) {
console.log('error with Textract', error)
}
})
Based on the AWS documentation I think the preferred architecture is to use three server-side actions:
- The first action posts the job to AWS and returns the job identifier.
- The second action queries the job status.
- The third action retrieves the completed job results.
The design pattern is then:
- Post the job using the first action
- Schedule a recursive workflow to run every “N” many seconds.
- This workflow queries the job status with the second action.
- Once success or fail returns end the workflow.
- On success retrieve the results with the third action.
Maybe AWS can accept a web-hook? In which case you could build a Bubble endpoint to conform to the AWS web-hook specification.