Skip to content

Commit

Permalink
feat : Image Uploader firebase to minio
Browse files Browse the repository at this point in the history
  • Loading branch information
pinomaker-hoo committed Nov 28, 2023
1 parent 95508ce commit 26936ad
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 11 deletions.
8 changes: 7 additions & 1 deletion .env.development
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ VITE_PROJECT_ID=dice-dev-a5b63
VITE_STORAGE_BUCKET=dice-dev-a5b63.appspot.com
VITE_MESSAGING_SENDER_ID=199773642283
VITE_APP_ID=1:199773642283:web:644baf30eae6d68fd1d46e
VITE_MEASUREMENT_ID=G-H1ZSMFWDEG
VITE_MEASUREMENT_ID=G-H1ZSMFWDEG

# MINIO Key
VITE_MINIO_ACCESS_KEY=rGoq9X6LhOM4Dgky7X9F
VITE_MINIO_SECRET_KEY=HqWnw2VKryLzuCA3epMT1JTY3HTEsWHUwq4gfQmy
VITE_MINIO_ENDPOINT=http://125.133.34.224:9000
VITE_MINIO_BUCKET_NAME=dice-dev
8 changes: 7 additions & 1 deletion .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ VITE_PROJECT_ID=
VITE_STORAGE_BUCKET=
VITE_MESSAGING_SENDER_ID=
VITE_APP_ID=
VITE_MEASUREMENT_ID=
VITE_MEASUREMENT_ID=

# MINIO Key
VITE_MINIO_ACCESS_KEY=
VITE_MINIO_SECRET_KEY=
VITE_MINIO_ENDPOINT=
VITE_MINIO_BUCKET_NAME=
8 changes: 7 additions & 1 deletion .env.staging
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ VITE_PROJECT_ID=
VITE_STORAGE_BUCKET=
VITE_MESSAGING_SENDER_ID=
VITE_APP_ID=
VITE_MEASUREMENT_ID=
VITE_MEASUREMENT_ID=

# MINIO Key
VITE_MINIO_ACCESS_KEY=
VITE_MINIO_SECRET_KEY=
VITE_MINIO_ENDPOINT=
VITE_MINIO_BUCKET_NAME=
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@mui/system": "^5.13.2",
"@reduxjs/toolkit": "^1.9.5",
"async-mutex": "^0.4.0",
"aws-sdk": "^2.1505.0",
"axios": "^1.6.1",
"firebase": "^10.3.1",
"lodash": "^4.17.21",
Expand Down
28 changes: 23 additions & 5 deletions src/components/imagePreview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { ChangeEvent, useEffect, useRef } from 'react'
// ** Mui Imports
import { Box } from '@mui/material'

// ** Utils Imports
import { uploadImage } from '@/utils/firebase-upload'
// ** Aws Imports
import AWS from 'aws-sdk'

interface PropsType {
image: string
Expand Down Expand Up @@ -38,10 +38,28 @@ const ImagePreview = ({
const file = event.target.files?.[0]

if (file) {
const response = await uploadImage(file)
if (response) {
setPath(response)
const s3 = new AWS.S3({
accessKeyId: import.meta.env.VITE_MINIO_ACCESS_KEY,
secretAccessKey: import.meta.env.VITE_MINIO_SECRET_KEY,
endpoint: import.meta.env.VITE_MINIO_ENDPOINT,
s3ForcePathStyle: true,
signatureVersion: 'v4',
})

const params = {
Bucket: import.meta.env.VITE_MINIO_BUCKET_NAME,
Key: file.name,
Body: file,
}

s3.upload(params, (err, data) => {
if (err) {
console.error(err)

return
}
setPath(data.Location)
})
}
}

Expand Down
3 changes: 3 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ export default defineConfig({
'@': resolve(__dirname, 'src'),
},
},
define: {
global: {},
},
})
Loading

0 comments on commit 26936ad

Please sign in to comment.