0.0.5 • Published 1 year ago

@revolt-digital/gallery-picker-s3 v0.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

:email: revoltMailer

A package to handle backend side of gallery picker integrated with AWS S3.

Todo

  • [] Tests

Usage

  • Install the package
  npm install @revolt-digital/galley-picker-s3
  # or
  yarn add @revolt-digital/galley-picker-s3
  • Step 1, create one handler file, where we can define the aws config file, Note: Define this transport in server.ts/app.ts (main expressjs file) to use it globally is not a good practice.
import { S3Service } from '@revolt-digital/galley-picker-s3';

const serviceS3 = new S3Service({
  accessKey: process.env.AWACCESKEYID,
  secretAccessKey: process.env.AWSECRETACCESSKEY,
  region: process.env.AWREGION,
  signatureVersion: process.env.AWSIGNATURE,
  bucket: process.env.AWS3BUCKET
});
  • Step 2, get AWS Upload Signed URL`.
app.post('/uploadurl', async (req:Request, res: Response)=> {
  try {
    let options = {
      fileName: "imagename_withoutextension",
      extension: "jpg",
      width: 500,
      height: 500,
      aspectRatio: '1/1',
      item: 0 //item 0 is considerated as the original item
    }
    const url = await serviceS3.getS3UploadSigned(options);
    res.send(`success: ${url}`)
  } catch (err) {
    throw err;
  }
})
  • Step 3, Delete Image in s3`.
app.post('/delete', async (req:Request, res: Response)=> {
  try {
    const url = await serviceS3.deleteObject(req.body.fileName)
    res.send(`success: ${url}`)
  } catch (err) {
    console.log(err);
  }
})
  • Step 4, List All objects with pagination`.
app.get('/list', async (req:Request, res: Response)=> {
  try {
    const page = 1;
    const limit = 500;
    const data = await serviceS3.getObjects(page, limit)
    res.send({sucess: true, data: data})
  } catch (err) {
    throw err;
  }
})

Running the example app

Run yarn install then yarn build in the root folder (the one with this README file).

Then move into the example folder cd example and run yarn install and yarn start.

Then go to http://localhost:8001/uploadurl

0.0.5

1 year ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.4

2 years ago

0.0.1

2 years ago