I am developing attachment download functionality in Forge Confluence application. I am encountering a strange bug that when downloading the same file but on Chrome or Microsoft Edge browser it shows error as below and cannot download, while if using FireFox or Safari browser it downloads successfully. This error does not happen consistently with all file types. That is, other files can still be downloaded on all browsers. The two images below are the results of me downloading the file Treadmill Running 300fps.avi having size 114.76MB in Chrome browser
I am using the GET URL to download attachment API in rest api conflunce version 1 to handle this file download. https://developer.atlassian.com/cloud/confluence/rest/v1/api-group-content---attachments/#api-wiki-rest-api-content-id-child-attachment-attachmentid-download-get.
And below is the code I am writing:
const onDownload = () => {
setLoading(true);
const handleFileName = (fileName, version) => {
const lastDotIndex = fileName.lastIndexOf('.');
if (lastDotIndex === -1) {
return `${fileName}-version${version}`;
}
const name = fileName.substring(0, lastDotIndex);
const extension = fileName.substring(lastDotIndex + 1);
return extension
? `${name}-version${version}.${extension}`
: `${name}-version${version}`;
};
var zip = new JSZip();
const downloadInfos = [];
const nameDuplicateCount = {};
selectedRows.forEach((row) => {
let detailAtt = tableList.find((att) => att.id === row.id);
let fileName = detailAtt?.fileName;
const extIndex = fileName.lastIndexOf(".");
const baseName = extIndex !== -1 ? fileName.slice(0, extIndex) : fileName;
const extension = extIndex !== -1 ? fileName.slice(extIndex) : "";
if (nameDuplicateCount[fileName] >= 0) {
nameDuplicateCount[fileName] += 1;
fileName = `${baseName} (${nameDuplicateCount[fileName]})${extension}`;
} else {
nameDuplicateCount[fileName] = 0;
}
row.versions.forEach((version) => {
let isCurrentVersion = version === detailAtt?.oldVersions?.length;
downloadInfos.push({
fileName: isCurrentVersion
? fileName
: handleFileName(fileName, version),
url: `/wiki/rest/api/content/${detailAtt?.parentId
}/child/attachment/${row.id}/download${isCurrentVersion ? '' : `?version=${version}`
}`,
});
});
});
function request(data) {
return new Promise(function (resolve) {
requestConfluence(data.url)
.then((res) => res.blob())
.then((blob) => {
const reader = new FileReader();
reader.readAsArrayBuffer(blob);
reader.onload = () => {
const arrayBuffer = reader.result;
zip.file(data.fileName, arrayBuffer);
resolve();
};
});
});
}
Promise.all(
downloadInfos.map(function (item, ind) {
return request(item, ind);
})
)
.then(function () {
zip
.generateAsync({
type: 'blob',
})
.then(function (content) {
saveAs(content, 'AttachmentsManager.zip');
setLoading(false);
});
flagSuccess('Attachments were successfully downloaded');
clearSelectedRows();
})
.catch(() => {
setLoading(false);
});
};
Please let me know if you have any ideas on this. Thanks in advance everyone!