List objects in a bucket

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

Script s3 Verified

by admin ยท 8/16/2022

The script

Submitted by admin Deno
Verified 376 days ago
1
import { removeObjectEmptyFields } from "https://deno.land/x/[email protected]/mod.ts";
2
import { S3Client } from "https://deno.land/x/[email protected]/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
  • Submitted by alvin chia107 Deno
    Created 1229 days ago
    1
    // import * as wmill from 'https://deno.land/x/windmill/index.ts'
    2
    
    
    3
    export async function main(x: string) {
    4
      return x
    5
    }