ASP.NET + Companion + Uppy

My requirement is to save a file from OneDrive to my local machine. I have written the code, but when I try to open the saved file, I get an error saying either the file is corrupted or the content is unavailable.

While debugging, I found that an error occurs at file.remote.url.

uppy.on(“upload”, async () => {
const files = uppy.getFiles();
const formData = buildFormDataWithFiles(files);
try {
const response = await uploadFiles(formData);
const responseBody = await response.json();
files.forEach((file) => {
uppy.emit(“upload-success”, file, { body: responseBody });
});
uppy.emit(“complete”, {
successful: files,
failed:
});
} catch (err) {
console.error(“Error during upload:”, err);
uppy.info(“Upload failed”, “error”, 5e3);
}
});
function buildFormDataWithFiles(files) {
const formElement = document.getElementById(“uploadForm”);
const formData = new FormData(formElement);
files.forEach((file) => {
if (file.isRemote && file.remote?.url) {
const blobPromise = fetchRemoteFileBlob(file);
file._blobPromise = blobPromise;
} else {
formData.append(“file”, file.data, file.name);
}
});
return formData;
}
async function fetchRemoteFileBlob(file) {
console.log(“Fetching remote file:”, file.name);
const response = await fetch(file.remote.url, {
method: file.remote.method || “POST”,
headers: file.remote.headers || {},
body: file.remote.body || null
});
return await response.blob();
}
async function uploadFiles(formData) {
const remoteBlobPromises = uppy.getFiles().filter((f2) => f2._blobPromise).map(async (file) => {
const blob = await file._blobPromise;
formData.append(“file”, blob, file.name);
});
await Promise.all(remoteBlobPromises);
return await fetch(“https://localhost:7035/Index?handler=UploadFile”, {
method: “POST”,
body: formData,
headers: {
“RequestVerificationToken”: $(‘input[name=“__RequestVerificationToken”]’).val()
}
});
}