Skip to content

Commit

Permalink
Merge pull request #1526 from BlueBrain/fix-multiple-file-download-in…
Browse files Browse the repository at this point in the history
…-resource-container

Fix multiple file download in resource container
  • Loading branch information
Dinika authored Mar 20, 2024
2 parents 70bca66 + a1f524e commit e18e42f
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/shared/components/Preview/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import TableViewerContainer from '../../containers/TableViewerContainer';
import { useSelector } from 'react-redux';
import { RootState } from '../../store/reducers';
import nexusUrlHardEncode from '../../utils/nexusEncode';
import * as Sentry from '@sentry/browser';

export const parseResourceId = (url: string) => {
const fileUrlPattern = /files\/([\w-]+)\/([\w-]+)\/(.*)/;
Expand Down Expand Up @@ -169,22 +170,27 @@ const Preview: React.FC<{
body: JSON.stringify(payload),
}
);
const archive = await nexus.httpGet({
path: `${apiEndpoint}/archives/${orgLabel}/${projectLabel}/${payload.archiveId}?ignoreNotFound=true`,
headers: { accept: 'application/zip, application/json' },
context: {
parseAs: 'blob',
},
});
const blob = archive as Blob;
const archiveName = `data-${payload.archiveId}.zip`;
downloadBlobHelper(blob, archiveName);

notification.success({
message: `Archive ${archiveName} downloaded successfully`,
});
} catch (error) {
Sentry.captureException({ error, message: 'Failed to download archive' });
notification.error({
message: 'Failed to download the file',
description: error.reason || error.message,
});
}
const archive = (await nexus.Archive.get(
orgLabel,
projectLabel,
archiveId,
{
as: 'x-tar',
}
)) as string;
const blob = new Blob([archive]);
downloadBlobHelper(blob, `${archiveId}.tar.gz`);
};

const downloadButton = (disabled: boolean) => {
Expand Down

0 comments on commit e18e42f

Please sign in to comment.