Skip to content

Commit

Permalink
Move signUpload
Browse files Browse the repository at this point in the history
  • Loading branch information
Lepozepo committed Oct 13, 2023
1 parent 83ff373 commit ae1a79a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
11 changes: 6 additions & 5 deletions packages/server/src/S3Up.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import S3 from 'aws-sdk/clients/s3';
import { S3Client } from '@aws-sdk/client-s3';
import signUpload from './signUpload';
import download from './download';
import upload from './upload';
Expand All @@ -8,11 +8,12 @@ export default class S3Up {
if (!props.bucket) throw new Error('bucket is required!');

this.props = props;
this.client = new S3({
this.client = new S3Client({
...props,
params: {
...props?.params,
Bucket: props.bucket,
credentials: {
accessKeyId: props.accessKeyId,
secretAccessKey: props.secretAccessKey,
...props?.credentials,
},
});
}
Expand Down
8 changes: 4 additions & 4 deletions packages/server/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export download from './download';
export S3Up from './S3Up';
export signUpload from './signUpload';
export upload from './upload';
export { default as download } from './download';
export { default as S3Up } from './S3Up';
export { default as signUpload } from './signUpload';
export { default as upload } from './upload';
15 changes: 6 additions & 9 deletions packages/server/src/signUpload.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { createPresignedPost } from '@aws-sdk/s3-presigned-post';

export default function signUpload(props, client) {
if (!props?.key) throw new Error(`key is required at signUpload({ key: ${props?.key} })`);
if (!props?.bucket) throw new Error(`bucket is required at signUpload({ bucket: ${props?.bucket} })`);

return new Promise((resolve, reject) => client.createPresignedPost({
return createPresignedPost(client, {
Bucket: props.bucket,
Key: props.key,
Expires: props.expires || 3600,
Conditions: props.conditions,
Fields: {
key: props.key,
...props.fields,
},
}, (err, res) => {
if (err) return reject(err);
return resolve(res);
}));
Fields: props.fields,
});
}

0 comments on commit ae1a79a

Please sign in to comment.