Skip to content

Instantly share code, notes, and snippets.

@amitkulhari26
Created October 21, 2020 07:42
Show Gist options
  • Select an option

  • Save amitkulhari26/b65d9a0b9ea7e7327591e88765faf28e to your computer and use it in GitHub Desktop.

Select an option

Save amitkulhari26/b65d9a0b9ea7e7327591e88765faf28e to your computer and use it in GitHub Desktop.
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