0
List objects in a bucket
One script reply has been approved by the moderators Verified

List all objects in a bucket and return them as a list

Created by admin 591 days ago Viewed 3782 times
0
Submitted by admin Deno
Verified 591 days ago
1
import { removeObjectEmptyFields } from "https://deno.land/x/windmill_helpers@v1.1.1/mod.ts";
2
import { S3Client } from "https://deno.land/x/s3_lite_client@0.5.0/mod.ts";
3

4
type S3 = {
5
  endPoint: string;
6
  port: number;
7
  useSSL: boolean;
8
  pathStyle: boolean;
9
  bucket: string;
10
  accessKey: string;
11
  secretKey: string;
12
  region: string;
13
};
14
export async function main(
15
  s3: S3,
16
  prefix?: string,
17
  bucketName?: string,
18
  maxResults?: number,
19
  pageSize?: number,
20
) {
21
  const s3client = new S3Client(s3);
22
  const options = removeObjectEmptyFields({
23
    prefix,
24
    bucketName,
25
    maxResults,
26
    pageSize,
27
  });
28
  const objects = s3client.listObjects(options);
29

30
  const result: any[] = [];
31
  for await (const obj of objects) {
32
    result.push(obj);
33
  }
34

35
  return result;
36
}
37

Other submissions