I had to generate presigned GET URLs for S3-compatible object storage service. Here’s a quick way to do it with Deno and the Minio JS SDK.
// generate.ts
import { Client } from 'npm:minio'
const minioClient = new Client({
endPoint: Deno.env.get('STORAGE_HOST'),
useSSL: true,
accessKey: Deno.env.get('STORAGE_AK'),
secretKey: Deno.env.get('STORAGE_SK'),
})
const bucket = Deno.env.get('STORAGE_BUCKET')
const key = Deno.args[0]
const url = await minioClient.presignedGetObject(bucket, key, 3600, {
'response-content-disposition': `attachment; filename="${key
.split('/')
.pop()}"`,
})
console.log(url)To run:
deno --env-file --allow-net --allow-env generate.ts hello.txt