Skip to content

Commit 25bd76a

Browse files
committed
resolve issue(#1)
1 parent 6501e62 commit 25bd76a

File tree

2 files changed

+57
-46
lines changed

2 files changed

+57
-46
lines changed

README.md

Lines changed: 54 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -63,44 +63,47 @@ You can define a default directory for uploads using the s3Config object
6363
```typescript
6464
/* AWS S3 Client */
6565
/* uploadFile.ts */
66-
import S3 from 'react-aws-s3-typescript';
66+
import ReactS3Client from 'react-aws-s3-typescript';
6767
import { s3Config } from './s3Config.ts';
6868

69-
/* Import s3 config object and call the constrcutor */
70-
const s3 = new S3(s3Config);
71-
72-
/* You can use the default directory defined in s3Config object
73-
* Or you can a define custom directory to upload when calling the
74-
* constructor using js/ts object destructuring.
75-
*
76-
* const s3 = new S3({
77-
* ...s3Config,
78-
* dirName: 'custom-directory'
79-
* });
80-
*
81-
*/
82-
83-
const filename = 'filename-to-be-uploaded'; /* Optional */
84-
85-
/* If you do not specify a file name, file will be uploaded using uuid generated
86-
* by short-UUID (https://www.npmjs.com/package/short-uuid)
87-
*/
88-
89-
90-
s3.uploadFile(file, filename).then((res) => {
91-
console.log(res);
92-
/*
93-
* {
94-
* Response: {
95-
* bucket: "bucket-name",
96-
* key: "directory-name/filename-to-be-uploaded",
97-
* location: "https:/your-aws-s3-bucket-url/directory-name/filename-to-be-uploaded"
98-
* }
99-
* }
100-
*/
101-
}).catch((err) => {
102-
console.log(err);
103-
})
69+
const uploadFile = async () => {
70+
/* Import s3 config object and call the constrcutor */
71+
const s3 = new ReactS3Client(s3Config);
72+
73+
/* You can use the default directory defined in s3Config object
74+
* Or you can a define custom directory to upload when calling the
75+
* constructor using js/ts object destructuring.
76+
*
77+
* const s3 = new ReactS3Client({
78+
* ...s3Config,
79+
* dirName: 'custom-directory'
80+
* });
81+
*
82+
*/
83+
84+
const filename = 'filename-to-be-uploaded'; /* Optional */
85+
86+
/* If you do not specify a file name, file will be uploaded using uuid generated
87+
* by short-UUID (https://www.npmjs.com/package/short-uuid)
88+
*/
89+
90+
try {
91+
const res = await s3.uploadFile(file, filename);
92+
93+
console.log(res);
94+
/*
95+
* {
96+
* Response: {
97+
* bucket: "bucket-name",
98+
* key: "directory-name/filename-to-be-uploaded",
99+
* location: "https:/your-aws-s3-bucket-url/directory-name/filename-to-be-uploaded"
100+
* }
101+
* }
102+
*/
103+
} catch (exception) {
104+
console.log(exception);
105+
/* handle the exception */
106+
}
104107

105108
/* End of uploadFile.ts */
106109
```
@@ -110,20 +113,25 @@ You can define a default directory for uploads using the s3Config object
110113
```typescript
111114
/* AWS S3 Client */
112115
/* deleteFile.ts */
113-
import S3 from 'react-aws-s3-typescript';
116+
import ReactS3Client from 'react-aws-s3-typescript';
114117
import { s3Config } from './s3Config.ts';
115118

116-
/* Import s3 config object and call the constrcutor */
117-
const s3 = new S3(s3Config);
119+
const deleteFile = async () => {
120+
/* Import s3 config object and call the constrcutor */
121+
const s3 = new ReactS3Client(s3Config);
118122

119-
/* Define the filepath from the root of the bucket to the file to be deleted */
120-
const filepath = 'directory-name/filename-to-be-deleted';
123+
/* Define the filepath from the root of the bucket to the file to be deleted */
124+
const filepath = 'directory-name/filename-to-be-deleted';
121125

122-
await s3.deleteFile(filepath).then((res) => {
123-
console.log('File deleted');
124-
}).catch((err) => {
125-
console.log(err);
126-
})
126+
try {
127+
await s3.deleteFile(filepath);
128+
129+
console.log('File deleted');
130+
} catch (exception) {
131+
console.log(exception);
132+
/* handle the exception */
133+
}
134+
}
127135

128136
/* End of deleteFile.ts */
129137
```

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import ReactS3Client from './react-aws-s3';
2+
3+
export default ReactS3Client;

0 commit comments

Comments
 (0)