I am new to react.
I am using gitHub api to send files to github repo.
const [fileChosen, setFileChosen] = useState(null);
const showFile = async (callBack) => {
try {
if (fileChosen) {
const base64url = await convertToBase64(fileChosen);
const octokit = new Octokit({
auth: "*************************************************",
});
await octokit.request(
`PUT /repos/HexaInnovLab/Rapidx_Documentation/contents/website/${
document.querySelector("#name")?.value
}/intro.md`,
{
owner: "HexaInnovLab",
repo: "Rapidx_Documentation",
message: "Using GitHub API",
committer: {
name: "Karan S",
email: "1000055393@hexaware.com",
},
content: base64url,
}
);
callBack();
} else {
callBack();
}
} catch (error) {
console.log(error);
}};
//This is the upload button where file is uploaded
<input
id="inputGroupFile"
ref={inputRef}
type="file"
class="form-control"
accept=".md,.mdx"
multiple
onChange={(event) =>
setFileChosen(event.target.files[0])
}
This method is working fine when a single file is uploaded. But when multiple files are uploaded, I need to use a for loop and iterate through the files uploaded and pass each file one afer the another to the api call.That is what i think from my java knowledge. Can i proceed that way or soemone explain how to use for loop and iterate thru files and give each file as input to the api call?