feat: implement S3 get and improve upload

pull/243/head
Josh Moore 1 year ago
parent 96c28fa7a9
commit 0f184c6630

@ -130,26 +130,38 @@ const doMultipartUpload = (file: Buffer, mimetype: string, fileKey: string): Pro
/** /**
* Uploads a file to your configured S3 provider * Uploads a file to your configured S3 provider
*/ */
export const uploadFileS3 = (file: Buffer, mimetype: string, fileKey: string): Promise<string> => new Promise(async (resolve, reject) => { export const uploadFileS3 = (file: Buffer, mimetype: string, fileKey: string): Promise<void> => new Promise(async (resolve, reject) => {
if (!s3readyCheck) return reject(NYR); if (!s3readyCheck) return reject(NYR);
try {
// todo: determine when to do multipart uplloads // todo: determine when to do multipart uplloads
await doObjectUpload(file, mimetype, fileKey); await doObjectUpload(file, mimetype, fileKey);
// todo: still need to find a way to access it // todo: still need to find a way to access it
resolve('hi'); resolve(void 0);
} catch (err) {
log.error('Failed to upload object to S3', fileKey);
console.error(err);
reject(err);
}
}); });
/** /**
* Gets a file from your configured S3 provider * Gets a file from your configured S3 provider
*/ */
export const getFileS3 = (): Promise<string> => new Promise((resolve, reject) => { export const getFileS3 = (fileKey: string): Promise<GetObjectCommandOutput> => new Promise(async (resolve, reject) => {
if (!s3readyCheck) return reject(NYR); if (!s3readyCheck) return reject(NYR);
// todo: S3 get logic try {
resolve(await s3()!.send(new GetObjectCommand({
log.warn('S3 Get', NYI); Bucket: UserConfig.config.s3!.bucket,
reject(NYI); Key: fileKey
})));
} catch (err) {
log.error('Failed to get object from S3', fileKey);
console.error(err);
reject(err);
}
}); });
/** /**

Loading…
Cancel
Save