mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-18 01:16:01 +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 bucket = getGridBucket(bucketName);
|
||||||
|
|
||||||
const fileSize = stats.size;
|
const fileSize = stats.size;
|
||||||
|
// 单块大小:尽可能大,但不超过 14MB,不小于512KB
|
||||||
const chunkSizeBytes = (() => {
|
const chunkSizeBytes = (() => {
|
||||||
// 计算理想块大小:文件大小 ÷ 目标块数(10)
|
// 计算理想块大小:文件大小 ÷ 目标块数(10)。 并且每个块需要小于 14MB
|
||||||
const idealChunkSize = Math.ceil(fileSize / 10);
|
const idealChunkSize = Math.min(Math.ceil(fileSize / 10), 14 * 1024 * 1024);
|
||||||
|
|
||||||
// 确保块大小至少为512KB
|
// 确保块大小至少为512KB
|
||||||
const minChunkSize = 512 * 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 { useI18n } from '@/web/context/I18n';
|
||||||
import { useContextSelector } from 'use-context-selector';
|
import { useContextSelector } from 'use-context-selector';
|
||||||
import { DatasetPageContext } from '@/web/core/dataset/context/datasetPageContext';
|
import { DatasetPageContext } from '@/web/core/dataset/context/datasetPageContext';
|
||||||
|
import { getErrText } from '@fastgpt/global/common/error/utils';
|
||||||
|
|
||||||
export type SelectFileItemType = {
|
export type SelectFileItemType = {
|
||||||
fileId: string;
|
fileId: string;
|
||||||
@@ -71,6 +72,7 @@ const FileSelector = ({
|
|||||||
{
|
{
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
files.map(async ({ fileId, file }) => {
|
files.map(async ({ fileId, file }) => {
|
||||||
|
try {
|
||||||
const { fileId: uploadFileId } = await uploadFile2DB({
|
const { fileId: uploadFileId } = await uploadFile2DB({
|
||||||
file,
|
file,
|
||||||
bucketName: BucketNameEnum.dataset,
|
bucketName: BucketNameEnum.dataset,
|
||||||
@@ -104,6 +106,19 @@ const FileSelector = ({
|
|||||||
: item
|
: item
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
} catch (error) {
|
||||||
|
setSelectFiles((state) =>
|
||||||
|
state.map((item) =>
|
||||||
|
item.id === fileId
|
||||||
|
? {
|
||||||
|
...item,
|
||||||
|
isUploading: false,
|
||||||
|
errorMsg: getErrText(error)
|
||||||
|
}
|
||||||
|
: item
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -9,12 +9,16 @@ import {
|
|||||||
Td,
|
Td,
|
||||||
Tbody,
|
Tbody,
|
||||||
Progress,
|
Progress,
|
||||||
IconButton
|
IconButton,
|
||||||
|
Box
|
||||||
} from '@chakra-ui/react';
|
} from '@chakra-ui/react';
|
||||||
import { ImportSourceItemType } from '@/web/core/dataset/type.d';
|
import { ImportSourceItemType } from '@/web/core/dataset/type.d';
|
||||||
import MyIcon from '@fastgpt/web/components/common/Icon';
|
import MyIcon from '@fastgpt/web/components/common/Icon';
|
||||||
import { useTranslation } from 'next-i18next';
|
import { useTranslation } from 'next-i18next';
|
||||||
import { useI18n } from '@/web/context/I18n';
|
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 = ({
|
export const RenderUploadFiles = ({
|
||||||
files,
|
files,
|
||||||
@@ -56,6 +60,14 @@ export const RenderUploadFiles = ({
|
|||||||
</Flex>
|
</Flex>
|
||||||
</Td>
|
</Td>
|
||||||
<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'}>
|
<Flex alignItems={'center'} fontSize={'xs'}>
|
||||||
<Progress
|
<Progress
|
||||||
value={item.uploadedFileRate}
|
value={item.uploadedFileRate}
|
||||||
@@ -72,6 +84,7 @@ export const RenderUploadFiles = ({
|
|||||||
/>
|
/>
|
||||||
{`${item.uploadedFileRate}%`}
|
{`${item.uploadedFileRate}%`}
|
||||||
</Flex>
|
</Flex>
|
||||||
|
)}
|
||||||
</Td>
|
</Td>
|
||||||
<Td>{item.sourceSize}</Td>
|
<Td>{item.sourceSize}</Td>
|
||||||
<Td>
|
<Td>
|
||||||
|
Reference in New Issue
Block a user