简体   繁体   English

如何使用“BatchPutDocument”服务将文件上传到 S3 存储桶?

[英]How to upload a file to S3 bucket using "BatchPutDocument" service?

we are running a javascript application with a search bar.我们正在运行一个带有搜索栏的 javascript 应用程序。 The content is searchable from S3 bucket of AWS.内容可从 AWS 的 S3 存储桶中搜索。 JavaScript application code: JavaScript 应用程序代码:

<html>

<head>
    <script src="aws-sdk-2.604.0.js"></script>
    <script>
        var kendra = new AWS.Kendra({
            apiVersion: '2019-02-03',
           // region: '*****',
            accessKeyId: '*********',
            secretAccessKey: '*******************'
        });

        function getResults() {

            var searchText = document.getElementById("searchBox").value;
            var params = {
                IndexId: '**************************',
                /* required */
                QueryText: searchText,
                PageNumber: '1',
                PageSize: '20'
            };
            kendra.query(params, function(err, data) {
                if (err) console.log(err, err.stack); // an error occurred
                else {
                    document.getElementById("results").innerText = data.ResultItems[0].DocumentTitle.Text;

                    console.log(data); // successful response
                }
            });

        }
    </script>
</head>

<body>
    <h1>This is Kendra application</h1>

    <input type="text" id="searchBox" />
    <button onclick="getResults()">Search</button>
    <div>
        <b>search results</b>
        <div id="results"></div>
    </div>
</body>

</html>

The above javascript application includes a search bar which gives data from S3 bucket.上面的 javascript 应用程序包含一个搜索栏,它提供来自 S3 存储桶的数据。 Now we need to upload a new file using the "BatchPutDocument" Service code give below.现在我们需要使用下面给出的“BatchPutDocument”服务代码上传一个新文件。 The uploaded document(html or pdf) should be searchable in the javascript application search box.上传的文档(html 或 pdf)应该可以在 javascript 应用程序搜索框中搜索到。

Note: we should not directly upload file in s3 bucket by going to AWS s3 bucket.注意:我们不应该通过转到 AWS s3 存储桶直接上传 s3 存储桶中的文件。 Is the code give below helpful or any alternative code available.下面给出的代码是否有帮助或是否有任何可用的替代代码。

var params = {
  Documents: [ /* required */
    {
      Id: 'STRING_VALUE', /* required */
      AccessControlList: [
        {
          Access: ALLOW | DENY, /* required */
          Name: 'STRING_VALUE', /* required */
          Type: USER | GROUP /* required */
        },
        /* more items */
      ],
      Attributes: [
        {
          Key: 'STRING_VALUE', /* required */
          Value: { /* required */
            DateValue: new Date || 'Wed Dec 31 1969 16:00:00 GMT-0800 (PST)' || 123456789,
            LongValue: 'NUMBER_VALUE',
            StringListValue: [
              'STRING_VALUE',
              /* more items */
            ],
            StringValue: 'STRING_VALUE'
          }
        },
        /* more items */
      ],
      Blob: Buffer.from('...') || 'STRING_VALUE' /* Strings will be Base-64 encoded on your behalf */,
      ContentType: PDF | HTML | MS_WORD | PLAIN_TEXT | PPT,
      S3Path: {
        Bucket: 'STRING_VALUE', /* required */
        Key: 'STRING_VALUE' /* required */
      },
      Title: 'STRING_VALUE'
    },
    /* more items */
  ],
  IndexId: 'STRING_VALUE', /* required */
  RoleArn: 'STRING_VALUE'
};
kendra.batchPutDocument(params, function(err, data) {
  if (err) console.log(err, err.stack); // an error occurred
  else     console.log(data);           // successful response
});

AWS Kendra allows you to index the documents in your Kendra index using available Connectors it offers or using BatchPutDocument API . AWS Kendra 允许您使用它提供的可用 连接器或使用BatchPutDocument API为 Kendra 索引中的文档编制索引。 When using BatchPutDocument API you can either pass the document inline to Kendra or pass an S3 URL of your document that you want to index.使用BatchPutDocument API时,您可以将文档内联传递给 Kendra,也可以传递要索引的文档的 S3 URL Once you have indexed your documents successfully, you will be able to perform a search using Kendra's Query API .成功为文档编制索引后,您将能够使用 Kendra 的查询 API执行搜索 I see that you already have some Javascript code to invoke Kendra's Query API, however, you could also refer to Kendra's provided sample React application if you are interested in building a React app.我看到您已经有一些 Javascript 代码来调用 Kendra 的查询 API,但是,如果您有兴趣构建 React 应用程序,也可以参考Kendra 提供的示例 React 应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将图像文件从 s3 存储桶上传到 cloudinary (nodejs) - How to upload an image file from an s3 bucket to cloudinary (nodejs) 如何将 CSV 文件上传到 scala 中给定的 s3 存储桶? - How to upload a CSV file to a given s3 bucket in scala? 如何使用 postdata preSigned Url 调用 Amazon S3 存储桶以使用空手道上传文件 - How to call Amazon S3 bucket using postdata preSigned Url to upload a file using Karate 如何使用 cURL 从 Amazon S3 存储桶中删除文件 - How to delete a file from amazon S3 bucket using cURL Windows 中的 AWS Cli 不会将文件上传到 s3 存储桶 - AWS Cli in Windows wont upload file to s3 bucket 如何使用 Boto3 下载 S3 存储桶的最新文件? - How to download the latest file of an S3 bucket using Boto3? 使用 Api Gateway、Lambda 函数将图像上传到 S3 存储桶 - Upload Image into S3 bucket using Api Gateway, Lambda funnction 如何在 laravel 5.5 的 s3 存储桶中上传图像 - How to upload image in s3 bucket in laravel 5.5 使用 AWS SDK NoSuchBucket 错误将文件上传到 S3 Bucket - Upload file to S3 Bucket with AWS SDK NoSuchBucket error 从 opencv 上传图片到 s3 bucket - Upload image from opencv to s3 bucket
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM