ai.awss3
函數
方法 | 參數 | 退貨 | 說明 |
|---|---|---|---|
getFile(bucketName, key, region, awsAccessKey, AwsSecretKey) | bucketName︰字串 索引鍵︰字串 區域︰字串 awsAcceskey︰字串 awsSecretKey︰字串 | 從 AWS S3 儲存桶擷取檔案。 | |
putFile(bucketName, key, region, awsAccessKey, AwsSecretKey) | bucketName︰字串 索引鍵︰字串 區域︰字串 awsAcceskey︰字串 awsSecretKey︰字串 | 將檔案放入 AWS S3 儲存桶。 | |
listKeys(bucketName, region, awsAccessKey, awsSecretKey) 不建議將其用於具有超過 5000 個鍵的儲存區。 | bucketName︰字串 區域︰字串 awsAcceskey︰字串 awsSecretKey︰字串 | 列出 AWS S3 儲存桶中的金鑰 (檔案)。 | |
listObjects(request, region, awsAccessKey, awsSecretKey) | 要求物件參數 請參閱 「 Amazon S3 要求文件」 以取得詳細資料。 bucketName︰String (必要)。 continuationToken︰表示清單會使用權杖在此儲存桶上繼續進行。從上一個回應取得的下一個延續權杖。 delimiter︰用於將索引鍵分組的字元。請參閱 「按階層列出索引鍵值」的 Amazon S3 文件。 編碼︰要在回應中使用的編碼方法。 fetchOwner︰設為 True 可列出具有每個索引鍵的擁有者。如果未指定,則擁有者為空值。 maxKeys︰回應中的索引鍵數目上限。 字首︰限制回覆以指定字首開頭的索引鍵。 requestPlayer︰字串 startAfter︰清單在此索引鍵之後開始。使用儲存區中的任何鍵。不可與 continueToken 同時設定。 回應物件參數 請參閱 「 Amazon S3 回應文件」 以取得詳細資料。 s3Objects︰找到的物件清單。 keyCount︰找到的物件數。 isTruncated︰指出是否有更多金鑰符合初始要求。可在要求中指定。AWS 預設為 1000。 nextContinuationToken︰在 isTruncated 為 True 時傳送,表示可列出儲存桶中的更多鍵。可使用此下一個繼續權杖繼續清單。 httpStatusCode: 名稱︰ 字首︰ maxKeys︰ 分隔符號︰ 常用字首︰ 編碼︰ continueToken︰ 開始後︰ | 列出 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 }