【问题标题】:Amazon Textract without using Amazon S3不使用 Amazon S3 的 Amazon Textract
【发布时间】:2021-11-01 04:53:59
【问题描述】:

我想使用 Amazon Textract 从 PDF 中提取信息(如 How to use the Amazon Textract with PDF files)。所有答案和 AWS 文档都要求输入是 Amazon S3 对象。

我是否可以在不将 PDF 上传到 Amazon S3 的情况下使用 Textract,而只是在 REST 调用中提供它们? (我必须将 PDF 存储在本地)。

【问题讨论】:

    标签: amazon-web-services api amazon-textract


    【解决方案1】:

    我将在考虑 Java API 的情况下回答这个问题。简短的回答是肯定的。

    如果您查看给定操作的 TextractAsyncClient Javadoc:

    https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/textract/TextractAsyncClient.html#analyzeDocument-software.amazon.awssdk.services.textract.model.AnalyzeDocumentRequest-

    它说:

    " 异步操作的文档也可以是PDF格式"

    这意味着 - 您可以像这样引用 PDF 文档并创建 AnalyzeDocumentRequest 对象(无需从 Amazon S3 存储桶中提取)。 :

    public static void analyzeDoc(TextractClient textractClient, String sourceDoc) {
    
            try {
                InputStream sourceStream = new FileInputStream(new File(sourceDoc));
                SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream);
    
                // Get the input Document object as bytes
                Document myDoc = Document.builder()
                        .bytes(sourceBytes)
                        .build();
    
                List<FeatureType> featureTypes = new ArrayList<FeatureType>();
                featureTypes.add(FeatureType.FORMS);
                featureTypes.add(FeatureType.TABLES);
    
                AnalyzeDocumentRequest analyzeDocumentRequest = AnalyzeDocumentRequest.builder()
                        .featureTypes(featureTypes)
                        .document(myDoc)
                        .build();
    
    // Use the TextractAsyncClient to perform an operation like analyzeDocument
    
    ...
    }
    

    【讨论】:

    猜你喜欢
    • 2019-09-24
    • 2021-02-10
    • 2019-11-01
    • 1970-01-01
    • 2015-10-30
    • 2022-01-17
    • 1970-01-01
    • 2012-03-12
    • 1970-01-01
    相关资源
    最近更新 更多