ai.awss3
函数
方法 | 参数 | 退货 | 描述 |
|---|---|---|---|
getFile(bucketName, key, region, awsAccessKey, AwsSecretKey) | BucketName:字符串 key:字符串 region: 字符串 awsAcceskey: 字符串 awsSecretKey:字符串 | 从 AWS S3 存储桶中检索文件。 | |
PutFile(bucketName, key, region, awsAccessKey, AwsSecretKey) | BucketName:字符串 key:字符串 doc:String region: 字符串 awsAcceskey: 字符串 awsSecretKey:字符串 | 将文件放入 AWS S3 存储桶中。 | |
listKeys(bucketName, region, awsAccessKey, awsSecretKey) 对于键数超过 5000 的存储桶,建议不要使用此选项。 | BucketName:字符串 region: 字符串 awsAcceskey: 字符串 awsSecretKey:字符串 | 列出 AWS S3 存储桶中的密钥(文件)。 | |
listObjects(request, region, awsAccessKey, awsSecretKey) | 请求对象参数 有关详细信息,请参见 Amazon S3 请求文档 。 BucketName:String(必填)。 completedToken:使用令牌指示列表在此存储桶上继续。从上一个响应中获取的 nextContinuationToken。 分隔符:用于对键进行分组的字符。请参见 “按层次结构排列 Amazon S3 列表键”文档。 编码:要在响应中使用的编码方法。 fetchOwner:设置为 true 可列出具有每个键的所有者。如果未指定,则所有者为 null。 maxKeys:响应中键的最大数量。 前缀:将响应限制为以指定前缀开头的键。 request播放器:字符串 startAfter:列表在此键之后开始。使用存储桶中的任意键。不能与 completedToken 同时设置。 响应对象参数 有关详细信息,请参见 Amazon S3 响应文档 。 s3Objects:找到的对象列表。 keyCount:找到的对象数。 isTruncated:指示是否有多个键与初始请求匹配。可以在请求中指定。AWS 默认值为 1000。 nextContinuationToken:当 isTruncated 为 true 时发送,表示可以列出存储桶中的更多键。可以使用此nextContinuationToken 继续列表。 httpStatusCode: 名称: 前缀: maxKeys: 分隔符: CommonPrefixes: 编码: completedToken: 开始时间晚于: | 列出 AWS S3 存储桶中的对象。允许在请求中使用参数来限制和筛选所提取的键。 |
- 示例
- // Invoke this method using 'Test connection' in Actions pane function testConnection(context) { exampleGetFile(context); exampleListKeys(context); return true; } //Example for getFile function exampleGetFile(context) { var bucketName = 'xxx'; var key = 'newfile.xml'; var awsAccessKey = 'xxx'; var awsSecretKey = 'xxx'; var region = 'xxx'; var doc = ai.xml.createDocument(); var myFile=ai.awss3.getFile(bucketName, key, region, awsAccessKey, awsSecretKey); ai.log.logVerbose("File contents are",JSON.stringify(myFile)); } //Column,Heading,Names\n,2016-05-31T00:00:00,49570.89,4110_Product_Revenue_Grp_A,Sales - Canada\n,..... //Example for listkeys function exampleListKeys(context) { var bucketName = 'xxx'; var key = 'test.csv'; var awsAccessKey = 'xxx'; var awsSecretKey = 'xxx'; var region = 'xxx'; var myFile=ai.awss3.listKeys(bucketName, region, awsAccessKey, awsSecretKey); ai.log.logVerbose("Keys are",JSON.stringify(myFile)); return true; } //Keys are ["attribute-import-demo.csv","cloadertest.csv"] //Example for putFile function exportData(context) { var bucketName = 'xxx'; var key = 'newfile.xml'; var awsAccessKey = 'xxx'; var awsSecretKey = 'xxx'; var region = 'xxx'; var doc = ai.xml.createDocument(); var requestEl = ai.xml.createElement('request'); doc.setRootElement(requestEl); ai.awss3.putFile(bucketName, key, doc.toString(), region, awsAccessKey, awsSecretKey); //This will create the "newfile.xml" with a single line "<request />" }
- 使用 listObjects 的示例
- 此示例展示了如何请求对象以及如何对结果进行分页。//Navigate to Designer Settings tab and add 2 "text" parameters from the Settings pane. //Enter awsAccessKey and awsSecretKey in the Name fileds and provide your keys in the Value field function processFiles(context) { // Retrieve access and secret keys from settings const awsAccessKey = context.getDataSource().getSetting('awsAccessKey').getValue(); const awsSecretKey = context.getDataSource().getSetting('awsSecretKey').getValue(); const region = 'us-west-1' // Create the request for objects, at a minimum a bucket name is required const request = { BucketName: 'xxx', Prefix: 'mydata/', // Return keys from this directory }; // Push all the keys into an array const keyNames = []; let processing = true; while (processing) { var response = ai.awss3.listObjects(request, region, awsAccessKey, awsSecretKey); for (const entry of response.s3Objects) { // Here we have a single key that can be processed as desired keyNames.push(entry.key); } if (response.isTruncated) { // If the response did not include all remaining results, use the // nextContinuationToken from the response in the next request request.ContinuationToken = response.nextContinuationToken; } else { // If the response did include all remaining results, exit the loop ai.log.logInfo('Response indicated no further keys available'); processing = false; } } ai.log.logInfo("List of Objects:"+JSON.stringify(keyNames)); //List of Objects:["attribute-import-demo (7).csv","cloadertest.csv"] }
- 参数请求示例
- 参数BucketName是唯一的必填值。Prefix表示目录。{ BucketName: 'ag-ccds-test', Prefix: 'samplenumber/', StartAfter: 'samplenumber/001_samplefile', MaxKeys: 3 }
- listObjects 示例
- 此 listOjbects 响应示例包含 8 个对象。{ "isTruncated": true, "s3Objects": [ { "eTag": "\"4c7507b8cf17a6650bcff6787ccd0915\"", "bucketName": "ag-ccds-test", "key": "archiveListing/archiveList_1575352592693.txt", "lastModified": "2019-12-03T15:56:34+10:00", "owner": null, "size": 1323, "storageClass": { "value": "STANDARD" } }, { "eTag": "\"b2addf641c43f17df4492524c834984c\"", "bucketName": "ag-ccds-test", "key": "archiveListing/archiveList_1575353843184.txt", "lastModified": "2019-12-03T16:17:24+10:00", "owner": null, "size": 1323, "storageClass": { "value": "STANDARD" } }, { "eTag": "\"b2addf641c43f17df4492524c834984c\"", "bucketName": "ag-ccds-test", "key": "archiveListing/archiveList_1575353844190.txt", "lastModified": "2019-12-03T16:17:25+10:00", "owner": null, "size": 1323, "storageClass": { "value": "STANDARD" } }, { "eTag": "\"b2addf641c43f17df4492524c834984c\"", "bucketName": "ag-ccds-test", "key": "archiveListing/archiveList_1575353845193.txt", "lastModified": "2019-12-03T16:17:26+10:00", "owner": null, "size": 1323, "storageClass": { "value": "STANDARD" } }, { "eTag": "\"b2addf641c43f17df4492524c834984c\"", "bucketName": "ag-ccds-test", "key": "archiveListing/archiveList_1575353846195.txt", "lastModified": "2019-12-03T16:17:27+10:00", "owner": null, "size": 1323, "storageClass": { "value": "STANDARD" } }, { "eTag": "\"b2addf641c43f17df4492524c834984c\"", "bucketName": "ag-ccds-test", "key": "archiveListing/archiveList_1575353847194.txt", "lastModified": "2019-12-03T16:17:28+10:00", "owner": null, "size": 1323, "storageClass": { "value": "STANDARD" } }, { "eTag": "\"b2addf641c43f17df4492524c834984c\"", "bucketName": "ag-ccds-test", "key": "archiveListing/archiveList_1575353848223.txt", "lastModified": "2019-12-03T16:17:29+10:00", "owner": null, "size": 1323, "storageClass": { "value": "STANDARD" } }, { "eTag": "\"b2addf641c43f17df4492524c834984c\"", "bucketName": "ag-ccds-test", "key": "archiveListing/archiveList_1575353849192.txt", "lastModified": "2019-12-03T16:17:30+10:00", "owner": null, "size": 1323, "storageClass": { "value": "STANDARD" } } ], "name": "ag-ccds-test", "prefix": "archiveListing/", "maxKeys": 8, "commonPrefixes": [], "delimiter": null, "encoding": null, "keyCount": 8, "continuationToken": null, "nextContinuationToken": "1Vut/ORdOSPdn8ZQdd8Z5nhNvlEfPkw0hkekFIDTVzk8Hn8jlttn/yIjkl67yK3RAUkPIoUHwDuiybia7Rx7YjVaRefLocnF4", "startAfter": null, "responseMetadata": { "requestId": "5ACCAA141D2F7D2B", "metadata": { "x-amz-id-2": "zlslMcRM+qj6SCKELuE2crlEzhc0eEFkpo5OC3Pzn9tMvtOYnaEkLoRQNj1m1SThPzI1lQ233Zo=" } }, "contentLength": -1, "httpStatusCode": 200 }