Skip to content

Instantly share code, notes, and snippets.

@sijad
Created September 3, 2020 08:55
Show Gist options
  • Save sijad/2f0a312cdddb06596e38590a8fcc1229 to your computer and use it in GitHub Desktop.
Save sijad/2f0a312cdddb06596e38590a8fcc1229 to your computer and use it in GitHub Desktop.
import { Client } from 'minio';
const maxAllowedSize = 1024 * 1024 * 50; // 50MB
const expireTime = 8 * 60 * 60; // 8 hour
const minioClient = new Client({
endPoint: S3_ENDPOINT,
port: 443,
accessKey: S3_ACCESS_KEY,
secretKey: S3_SECRET_KEY,
useSSL: true,
});
function createNewLink(name: string, mime: string): Promise<PostPolicyResult> {
return new Promise((resolve, reject) => {
const policy = minioClient.newPostPolicy();
const expires = new Date();
expires.setSeconds(expireTime);
policy.setExpires(expires);
policy.setContentLengthRange(1, maxAllowedSize);
policy.setBucket(S3_BUCKET_NAME);
policy.setKey(name);
policy.setContentType(mime);
minioClient.presignedPostPolicy(policy, function(err, data) {
if (err) {
reject(err);
}
resolve(data);
});
});
}
createNewLink('myfolder/myfile.txt', 'text/csv').then(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment