mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-21 11:43:56 +00:00
fix: mongodb file oversize (#4594)
This commit is contained in:
@@ -16,4 +16,5 @@ weight: 793
|
||||
|
||||
## 🐛 修复
|
||||
|
||||
1. 文件上传分块大小限制,避免超出 MongoDB 限制。
|
||||
|
||||
|
@@ -65,9 +65,10 @@ export async function uploadFile({
|
||||
const bucket = getGridBucket(bucketName);
|
||||
|
||||
const fileSize = stats.size;
|
||||
// 单块大小:尽可能大,但不超过 14MB,不小于512KB
|
||||
const chunkSizeBytes = (() => {
|
||||
// 计算理想块大小:文件大小 ÷ 目标块数(10)
|
||||
const idealChunkSize = Math.ceil(fileSize / 10);
|
||||
// 计算理想块大小:文件大小 ÷ 目标块数(10)。 并且每个块需要小于 14MB
|
||||
const idealChunkSize = Math.min(Math.ceil(fileSize / 10), 14 * 1024 * 1024);
|
||||
|
||||
// 确保块大小至少为512KB
|
||||
const minChunkSize = 512 * 1024; // 512KB
|
||||
|
@@ -16,6 +16,7 @@ import { ImportSourceItemType } from '@/web/core/dataset/type';
|
||||
import { useI18n } from '@/web/context/I18n';
|
||||
import { useContextSelector } from 'use-context-selector';
|
||||
import { DatasetPageContext } from '@/web/core/dataset/context/datasetPageContext';
|
||||
import { getErrText } from '@fastgpt/global/common/error/utils';
|
||||
|
||||
export type SelectFileItemType = {
|
||||
fileId: string;
|
||||
@@ -71,6 +72,7 @@ const FileSelector = ({
|
||||
{
|
||||
await Promise.all(
|
||||
files.map(async ({ fileId, file }) => {
|
||||
try {
|
||||
const { fileId: uploadFileId } = await uploadFile2DB({
|
||||
file,
|
||||
bucketName: BucketNameEnum.dataset,
|
||||
@@ -104,6 +106,19 @@ const FileSelector = ({
|
||||
: item
|
||||
)
|
||||
);
|
||||
} catch (error) {
|
||||
setSelectFiles((state) =>
|
||||
state.map((item) =>
|
||||
item.id === fileId
|
||||
? {
|
||||
...item,
|
||||
isUploading: false,
|
||||
errorMsg: getErrText(error)
|
||||
}
|
||||
: item
|
||||
)
|
||||
);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
@@ -9,12 +9,16 @@ import {
|
||||
Td,
|
||||
Tbody,
|
||||
Progress,
|
||||
IconButton
|
||||
IconButton,
|
||||
Box
|
||||
} from '@chakra-ui/react';
|
||||
import { ImportSourceItemType } from '@/web/core/dataset/type.d';
|
||||
import MyIcon from '@fastgpt/web/components/common/Icon';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import { useI18n } from '@/web/context/I18n';
|
||||
import MyTooltip from '@fastgpt/web/components/common/MyTooltip';
|
||||
import MyTag from '@fastgpt/web/components/common/Tag/index';
|
||||
import { QuestionOutlineIcon } from '@chakra-ui/icons';
|
||||
|
||||
export const RenderUploadFiles = ({
|
||||
files,
|
||||
@@ -56,6 +60,14 @@ export const RenderUploadFiles = ({
|
||||
</Flex>
|
||||
</Td>
|
||||
<Td>
|
||||
{item.errorMsg ? (
|
||||
<MyTooltip label={item.errorMsg}>
|
||||
<MyTag colorSchema={'red'}>
|
||||
<Box mr={1}>{t('common:common.Error')}</Box>
|
||||
<MyIcon name={'help'} w={'0.9rem'} color={'red.500'} />
|
||||
</MyTag>
|
||||
</MyTooltip>
|
||||
) : (
|
||||
<Flex alignItems={'center'} fontSize={'xs'}>
|
||||
<Progress
|
||||
value={item.uploadedFileRate}
|
||||
@@ -72,6 +84,7 @@ export const RenderUploadFiles = ({
|
||||
/>
|
||||
{`${item.uploadedFileRate}%`}
|
||||
</Flex>
|
||||
)}
|
||||
</Td>
|
||||
<Td>{item.sourceSize}</Td>
|
||||
<Td>
|
||||
|
Reference in New Issue
Block a user