I am creating an app for file storage
When a user uploads the file it is stored in the MongoDB in buffer format
When a user requests the file the same buffer is sent into the response to the user from the server.
When that response is received, react native throws an error of
RangeError: Property storage exceeds 196607 properties
which ultimately crashes the app or hangs it
Here is my downloadFile code
import { Helpers } from '#/utils';
import { get } from 'lodash';
const downloadFile = async (fileDetails, isConnected, downloadFileMutation) => {
const channelId =
await Helpers.createChannelForProgressNotificationOfUploadingAndDownloadingFiles();
const notificationId =
await Helpers.uploadAndDownloadFileProgressNotification(
'downloadFile',
0,
channelId,
Constants.NOTIFICATION_STATUS.START,
`Downloading ${fileDetails.name} File`
);
downloadFileMutation.mutate(
{
files: [fileDetails._id],
},
{
onSuccess: async (filesDetails) => {
console.log('filesDetails', filesDetails);
await Helpers.cancelNotification(notificationId);
Helpers.uploadAndDownloadFileProgressNotification(
'downloadFile',
1,
channelId,
Constants.NOTIFICATION_STATUS.END,
`${fileDetails.name} downloaded successfully`,
'click to view file'
);
const listOfFileNamesWithBuffer = filesDetails.fileBuffers.map(
(data) => ({
name: data.file.originalname,
buffer: data.file.buffer.data,
})
);
await Helpers.downloadAndStoreFile(listOfFileNamesWithBuffer);
},
onError: ({
response: {
data: { error },
},
}) => {
Helpers.toastMessage(
get(error, 'description', Constants.COMMON_ERROR_MESSAGE),
'error'
);
},
}
);
};
export default downloadFile;
And below is my downloadFileMutation
import { encryptedLockerAxiosClient } from '#/utils';
import { getFilesApiEndpoint } from '#/config/routes';
const getFile = (fileIds, authToken) =>
encryptedLockerAxiosClient
.post(
getFilesApiEndpoint,
{
...fileIds,
},
{
headers: {
Authorization: authToken,
},
}
)
.then((data) => ({
fileBuffers: data.data,
status: data.status,
}));
const useGetFile = (authToken, progressCallback, options = {}) => {
const mutation = useMutation((fileIds) => getFile(fileIds, authToken), {
...options,
});
return mutation;
};
export default useGetFile;