-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb1eb9d
commit 23db67c
Showing
18 changed files
with
348 additions
and
68 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const API_MEDIA = { | ||
/** | ||
* @author Châu Gia Bảo | ||
* @created_at 24/03/2023 | ||
* @descriptionKey API Upload Media | ||
*/ | ||
UPLOAD_MEDIA: '/media/v1/media/private/upload', | ||
/** | ||
* @author Châu Gia Bảo | ||
* @created_at 24/03/2023 | ||
* @descriptionKey API Remove Media | ||
*/ | ||
REMOVE_MEDIA: '/media/v1/media/private/remove', | ||
}; | ||
export default API_MEDIA; |
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
45 changes: 45 additions & 0 deletions
45
frontend-manager-cms/src/custom_hook/useUpload/uploadMediaCloud.jsx
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//!LIBRARY | ||
import { useDispatch } from 'react-redux'; | ||
|
||
//!REDUX THUNK | ||
import { Upload_Media_Initial } from 'redux/media/upload_remove_media/media_thunk'; | ||
|
||
//!SHARE | ||
import CONSTANTS from 'configs/constants'; | ||
import NOTIFICATION from 'utils/notification'; | ||
|
||
const useUploadCloud = () => { | ||
const dispatch = useDispatch(); | ||
|
||
const handleUpload = (e) => { | ||
e.preventDefault(); | ||
try { | ||
// Check input file | ||
const file = e.target.files[0]; | ||
if (!file) return NOTIFICATION.notifyError('File not Exists'); | ||
|
||
if (file.size > 1024 * 1024) | ||
// 1mb | ||
return NOTIFICATION.notifyError('Size too large !'); | ||
|
||
//Check type file | ||
if (file.type !== CONSTANTS.MEDIA_TYPE.JPEG && file.type !== CONSTANTS.MEDIA_TYPE.PNG) { | ||
// 1mb | ||
return NOTIFICATION.notifyError('File format is incorrect.'); | ||
} | ||
|
||
// Create Form data save image computer | ||
let formData = new FormData(); | ||
formData.append(CONSTANTS.MEDIA_TYPE.FILE, file); | ||
|
||
//Action upload | ||
dispatch(Upload_Media_Initial({ formData })); | ||
} catch (error) { | ||
console.log(error); | ||
NOTIFICATION.notifyError(error.response.data.msg); | ||
} | ||
}; | ||
return { handleUpload }; | ||
}; | ||
|
||
export default useUploadCloud; |
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
Oops, something went wrong.