add services/capture/src/s3/client.js
This commit is contained in:
parent
75ef8a4ed8
commit
dfffca879a
1 changed files with 32 additions and 0 deletions
32
services/capture/src/s3/client.js
Normal file
32
services/capture/src/s3/client.js
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
import { S3Client } from '@aws-sdk/client-s3';
|
||||||
|
import { Upload } from '@aws-sdk/lib-storage';
|
||||||
|
|
||||||
|
const s3Client = new S3Client({
|
||||||
|
endpoint: process.env.S3_ENDPOINT,
|
||||||
|
region: process.env.AWS_REGION || 'us-east-1',
|
||||||
|
credentials: {
|
||||||
|
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
||||||
|
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
||||||
|
},
|
||||||
|
forcePathStyle: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an upload stream for streaming data to S3
|
||||||
|
* @param {string} bucket - S3 bucket name
|
||||||
|
* @param {string} key - S3 object key
|
||||||
|
* @param {Stream} body - ReadableStream to upload
|
||||||
|
* @returns {Promise} Upload promise
|
||||||
|
*/
|
||||||
|
export function createUploadStream(bucket, key, body) {
|
||||||
|
return new Upload({
|
||||||
|
client: s3Client,
|
||||||
|
params: {
|
||||||
|
Bucket: bucket,
|
||||||
|
Key: key,
|
||||||
|
Body: body,
|
||||||
|
},
|
||||||
|
}).done();
|
||||||
|
}
|
||||||
|
|
||||||
|
export default s3Client;
|
||||||
Loading…
Reference in a new issue