-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/Upload_media #74
Open
Smokashi23
wants to merge
6
commits into
master
Choose a base branch
from
Feature/Upload_media
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+111
−34
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
66c4ca3
-Added feature can upload pdf ,vedio, excel
Smokashi23 bb53114
-Added function to open the file in new tab
Smokashi23 3c06839
-Removed the unnecessary image files
Smokashi23 87e85f2
- Added the download icon for download button
Smokashi23 6341edf
-Added note for the upload fize size limit
Smokashi23 0dcf7bb
Revert "-Added note for the upload fize size limit"
Smokashi23 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,24 +4,85 @@ import { s3GetPresignedUrl} from 'apis/utils/mediaUpload/awsmedia'; | |
import Loader from 'modules/Auth/components/Loader'; | ||
import { useEffect, useState } from 'react'; | ||
|
||
export const ImageS3Tag = ({ path }) => { | ||
const [srcImg, setSrcImg] = useState<string | undefined>(); | ||
export const MediaS3Tag = ({ path }: { path: string }) => { | ||
const [srcFile, setSrcFile] = useState<string | undefined>(); | ||
const [isLoading, setIsLoading] = useState<Boolean>(false); | ||
const [fileType, setFileType] = useState<string | undefined>(); | ||
|
||
useEffect(() => { | ||
setIsLoading(true); | ||
s3GetPresignedUrl(path) | ||
.then((img) => { | ||
.then((assetUrl) => { | ||
setIsLoading(false); | ||
setSrcImg(img); | ||
setSrcFile(assetUrl); | ||
const baseUrl = assetUrl.split('?')[0]; | ||
const extension = baseUrl.split('.').pop()?.toLowerCase(); | ||
|
||
if (extension === 'pdf') { | ||
setFileType('pdf'); | ||
} else if (['jpg', 'jpeg', 'png', 'gif'].includes(extension || '')) { | ||
setFileType('image'); | ||
} else if (['xls', 'xlsx'].includes(extension)) { | ||
setFileType('excel'); | ||
} else if (['mp4', 'webm', 'ogg'].includes(extension)) { | ||
setFileType('video'); | ||
} else { | ||
setFileType('unsupported'); | ||
} | ||
}) | ||
.catch((e) => { | ||
console.log('unable to fetch', e); | ||
setIsLoading(false); | ||
}); | ||
}, []); | ||
return isLoading ? ( | ||
<CircularProgress /> | ||
) : ( | ||
<img src={srcImg} alt='Image' width={'200px'} height={'200px'}></img> | ||
); | ||
}, [path]); | ||
|
||
if (isLoading) { | ||
return <CircularProgress />; | ||
} | ||
|
||
if (fileType === 'pdf') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should'nt be dependent on file extension to determine file type. |
||
return ( | ||
<img | ||
src="/images/pdf.png" | ||
alt="PDF Thumbnail" | ||
width="50px" | ||
height="50px" | ||
onClick={() => window.open(srcFile, '_blank')} | ||
style={{ cursor: 'pointer' }} | ||
/> | ||
); | ||
} else if (fileType === 'image') { | ||
return ( | ||
<img | ||
src={srcFile} | ||
alt="File" | ||
width="200px" | ||
height="200px" | ||
/> | ||
); | ||
} else if (fileType === 'excel') { | ||
return ( | ||
<img | ||
src="/images/sheets.png" | ||
alt="Excel Thumbnail" | ||
width="50px" | ||
height="50px" | ||
onClick={() => window.open(srcFile, '_blank')} | ||
style={{ cursor: 'pointer' }} | ||
/> | ||
); | ||
} else if (fileType === 'video') { | ||
const videoType = srcFile?.split('.').pop()?.toLowerCase() === 'mp4' ? 'video/mp4' : 'video/webm'; | ||
return ( | ||
<video | ||
width="400" | ||
controls | ||
style={{ cursor: 'pointer' }}> | ||
<source src={srcFile} type={videoType} /> | ||
Your browser does not support the video tag. | ||
</video> | ||
); | ||
} else { | ||
return <p>Unsupported file type</p>; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import { Box } from '@mui/system'; | |
import { IconButton, Typography } from '@mui/material'; | ||
import CloseIcon from '@mui/icons-material/Close'; | ||
import { useState } from 'react'; | ||
import { ALLOWED_TYPES } from './constants'; | ||
import { ALLOWED_TYPES, MAX_FILE_SIZE } from './constants'; | ||
|
||
export const UploadBucket = ({ | ||
isLoading, | ||
|
@@ -32,11 +32,20 @@ export const UploadBucket = ({ | |
|
||
if (invalidFile) { | ||
setErrorMessage(`Invalid file type: ${invalidFile.name}`); | ||
} else { | ||
setErrorMessage(null); | ||
handleChange(selectedFiles); | ||
return; | ||
} | ||
|
||
const oversizedFile = selectedFiles.find((file) => file.size > MAX_FILE_SIZE); | ||
|
||
if (oversizedFile) { | ||
setErrorMessage(`File size exceeds limit: ${oversizedFile.name}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return; | ||
} | ||
|
||
setErrorMessage(null); | ||
handleChange(selectedFiles); | ||
}; | ||
|
||
return ( | ||
<Box> | ||
<input | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
export const ALLOWED_TYPES = ['image/png', 'image/jpeg', 'image/jpg']; | ||
export const ALLOWED_TYPES = ['image/png', 'image/jpeg', 'image/jpg', 'application/pdf','video/mp4', 'vedio/webm', 'vedio/ogg', 'application/vnd.ms-excel', | ||
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']; | ||
|
||
export const MAX_FILE_SIZE = 5 * 1024 * 1024; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the type definition affects readability in this case