Created
October 21, 2020 07:42
-
-
Save amitkulhari26/b65d9a0b9ea7e7327591e88765faf28e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| const processActionClick = () => { | |
| // for progress bar | |
| const options = { | |
| onUploadProgress: (progressEvent) => { | |
| const { loaded, total } = progressEvent; | |
| let percent = Math.floor((loaded * 100) / total); | |
| setUploadPercentage(percent); | |
| }, | |
| headers: { | |
| "rx-a": token, | |
| }, | |
| }; | |
| // Create an object of formData | |
| const formData = new FormData(); | |
| formData.append("environment", DEVELOPMENT); | |
| // Update the formData object | |
| for (let i = 0; i < selectedFiles.length; i++) { | |
| formData.append("audioFile", selectedFiles[i]); | |
| } | |
| const bookId = book.value; | |
| axios | |
| .post(`${AWS_ROUTES_UPLOAD_AUDIO}/${bookId}`, formData, options) | |
| .then((res) => { | |
| setUploadPercentage(uploadPercentage); | |
| // dispatch({ type: UPLOAD_PERCENTAGE, payload: state.uploadPercentage }); | |
| toast.success("Audio Uploaded"); | |
| setInputKey(Date.now()); | |
| setUploadPercentage(0); | |
| setSelectedFiles([]); | |
| setBook(""); | |
| }) | |
| .catch((err) => { | |
| handleError(err); | |
| }); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment