Skip to content

Commit 9ff37dd

Browse files
authored
Merge pull request #19 from mediamonks/feature/load-config-with-object
adding the ability to just add a config object is stead of a file location.
2 parents 662adc4 + 0756b8f commit 9ff37dd

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ import Uploader from 's3-batch-upload';
7070

7171
const files = await new Uploader({
7272
config: './config/configS3.json', // can also use environment variables
73+
config: { // or you can use a object
74+
accessKeyId: "__EMPTY__",
75+
secretAccessKey: "__EMPTY__",
76+
region: "us-east-1"
77+
},
7378
bucket: 'bucket-name',
7479
localPath: './files',
7580
remotePath: 'remote/path/in/bucket',

src/lib/Uploader.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import streamBatch from './batch';
22
import S3 from 'aws-sdk/clients/s3';
3+
import { ConfigurationOptions } from 'aws-sdk/lib/config';
34

45
const glob = require('glob');
56
const minimatch = require('minimatch');
@@ -15,7 +16,7 @@ export type Options = {
1516
bucket: string;
1617
localPath: string;
1718
remotePath: string;
18-
config?: string;
19+
config?: string | ConfigurationOptions;
1920
glob?: string;
2021
globOptions?: object;
2122
concurrency?: number;
@@ -46,7 +47,13 @@ export default class Uploader {
4647
};
4748

4849
if (this.options.config) {
49-
AWS.config.loadFromPath(this.options.config);
50+
if (typeof this.options.config === 'string') {
51+
AWS.config.loadFromPath(this.options.config);
52+
} else if (typeof this.options.config === 'object') {
53+
AWS.config.constructor(this.options.config);
54+
} else {
55+
throw new Error('unsupported config is passed as a argument.');
56+
}
5057
}
5158

5259
// TODO: more checks on other options?

0 commit comments

Comments
 (0)