Add function to download and decrypt a file

This commit is contained in:
Vishnu Mohandas 2020-10-19 08:37:16 +05:30
parent 01e57a212b
commit 580ce23c17

View file

@ -92,3 +92,16 @@ export const getPreview = async (token: string, file: file) => {
file.key);
return URL.createObjectURL(new Blob([decrypted]));
}
export const getFile = async (token: string, file: file) => {
const resp = await HTTPService.get(
`${ENDPOINT}/files/download/${file.id}`,
{ token }, null, { responseType: 'arraybuffer' },
);
const worker = await new CryptoWorker();
const decrypted: any = await worker.decryptFile(
new Uint8Array(resp.data),
await worker.fromB64(file.file.decryptionHeader),
file.key);
return URL.createObjectURL(new Blob([decrypted]));
}