showing results for - "react aws s3 npm"
Tatiana
19 Oct 2019
1import S3 from 'react-aws-s3';
2
3const config = {
4    bucketName: 'myBucket',
5    dirName: 'media', /* optional */
6    region: 'eu-west-1',
7    accessKeyId: 'JAJHAFJFHJDFJSDHFSDHFJKDSF',
8    secretAccessKey: 'jhsdf99845fd98qwed42ebdyeqwd-3r98f373f=qwrq3rfr3rf',
9    s3Url: 'https:/your-custom-s3-url.com/', /* optional */
10}
11
12const ReactS3Client = new S3(config);
13/*  Notice that if you don't provide a dirName, the file will be automatically uploaded to the root of your bucket */
14
15/* This is optional */
16const newFileName = 'test-file';
17
18ReactS3Client
19    .uploadFile(file, newFileName)
20    .then(data => console.log(data))
21    .catch(err => console.error(err))
22
23  /**
24   * {
25   *   Response: {
26   *     bucket: "myBucket",
27   *     key: "image/test-image.jpg",
28   *     location: "https://myBucket.s3.amazonaws.com/media/test-file.jpg"
29   *   }
30   * }
31   */
32});
33
Kian
13 Mar 2020
1npm install --save react-aws-s3
2
Brenna
23 May 2020
1import S3 from 'react-aws-s3';
2
3
4const config = {
5    bucketName: 'myBucket',
6    dirName: 'media', /* optional */
7    region: 'eu-west-1',
8    accessKeyId: 'JAJHAFJFHJDFJSDHFSDHFJKDSF',
9    secretAccessKey: 'jhsdf99845fd98qwed42ebdyeqwd-3r98f373f=qwrq3rfr3rf',
10    s3Url: 'https:/your-custom-s3-url.com/', /* optional */
11}
12
13const ReactS3Client = new S3(config);
14
15const filename = 'hello-world.docx';
16
17/* If the file that you want to delete it's in your bucket's root folder, don't provide any dirName in the config object */
18
19//In this case the file that we want to delete is in the folder 'photos' that we referred in the config object as the dirName
20
21ReactS3Client
22    .deleteFile(filename)
23    .then(response => console.log(response))
24    .catch(err => console.error(err))
25
26  /**
27   * {
28   *   Response: {
29   *      ok: true,
30          status: 204,
31          message: 'File deleted',
32          fileName: 'hello-world.docx'
33   *   }
34   * }
35   */
36});
37
Safiya
03 Sep 2017
1yarn add react-aws-s3
2