diff --git a/es/components/extraFile/upload/index.js b/es/components/extraFile/upload/index.js index 0d48a62b3..633c33c32 100644 --- a/es/components/extraFile/upload/index.js +++ b/es/components/extraFile/upload/index.js @@ -74,6 +74,7 @@ export default OakComponent({ entityId: '', theme: 'image', style: '', // 各渠道图片样式 + chunkOptions: undefined, }, lifetimes: { async detached() { @@ -183,9 +184,7 @@ export default OakComponent({ await this.features.extraFile.autoUpload({ extraFile: updateData, file: file, - chunkOptions: { - chunkSize: 100 * 1024 * 1024, // 100MB - }, + chunkOptions: this.props.chunkOptions, getPercent: (percentage) => { const currentFiles = this.state.files; const index = currentFiles.findIndex((ele) => ele.objectId === diff --git a/es/utils/files/slice.js b/es/utils/files/slice.js index b0f836f74..012bbbb1e 100644 --- a/es/utils/files/slice.js +++ b/es/utils/files/slice.js @@ -24,6 +24,7 @@ export async function sliceFile(file, chunkSize, partCount) { export async function sliceFileForMp(filePath, chunkSize, partCount) { const fs = wx.getFileSystemManager(); const tempDir = `${wx.env.USER_DATA_PATH}/oak_upload_temp`; + assert(chunkSize <= 10 * 1024 * 1024, '小程序下,单个分片大小不能超过 10MB'); // 微信小程序限制单个文件不能超过10MB // 确保临时目录存在 try { fs.accessSync(tempDir); diff --git a/lib/utils/files/slice.js b/lib/utils/files/slice.js index 60f343c3a..4196cf0e1 100644 --- a/lib/utils/files/slice.js +++ b/lib/utils/files/slice.js @@ -30,6 +30,7 @@ async function sliceFile(file, chunkSize, partCount) { async function sliceFileForMp(filePath, chunkSize, partCount) { const fs = wx.getFileSystemManager(); const tempDir = `${wx.env.USER_DATA_PATH}/oak_upload_temp`; + (0, assert_1.default)(chunkSize <= 10 * 1024 * 1024, '小程序下,单个分片大小不能超过 10MB'); // 微信小程序限制单个文件不能超过10MB // 确保临时目录存在 try { fs.accessSync(tempDir); diff --git a/src/components/extraFile/upload/index.ts b/src/components/extraFile/upload/index.ts index 840c8a76f..e8756d801 100644 --- a/src/components/extraFile/upload/index.ts +++ b/src/components/extraFile/upload/index.ts @@ -1,5 +1,6 @@ import { EntityDict } from '../../../oak-app-domain'; -import { FileState } from '../../../features/extraFile'; +import { ChunkOptions, +FileState } from '../../../features/extraFile'; import { EntityDict as BaseEntityDict } from 'oak-domain/lib/types/Entity'; import { ReactComponentProps } from 'oak-frontend-base/lib/types/Page'; import { generateNewId } from 'oak-domain/lib/utils/uuid'; @@ -105,6 +106,7 @@ export default OakComponent({ entityId: '', theme: 'image' as Theme, style: '', // 各渠道图片样式 + chunkOptions: undefined as ChunkOptions | undefined, }, lifetimes: { async detached() { @@ -245,9 +247,7 @@ export default OakComponent({ { extraFile: updateData as EntityDict['extraFile']['OpSchema'], file: file, - chunkOptions: { - chunkSize: 100 * 1024 * 1024, // 100MB - }, + chunkOptions: this.props.chunkOptions, getPercent: (percentage: number) => { const currentFiles = this.state.files as EnhancedExtraFile[]; const index = currentFiles.findIndex( diff --git a/src/utils/files/slice.ts b/src/utils/files/slice.ts index 92481d05c..921400f6a 100644 --- a/src/utils/files/slice.ts +++ b/src/utils/files/slice.ts @@ -26,6 +26,8 @@ export async function sliceFile(file: string | File, chunkSize: number, partCoun export async function sliceFileForMp(filePath: string, chunkSize: number, partCount: number): Promise { const fs = wx.getFileSystemManager(); const tempDir = `${wx.env.USER_DATA_PATH}/oak_upload_temp`; + + assert(chunkSize <= 10 * 1024 * 1024, '小程序下,单个分片大小不能超过 10MB'); // 微信小程序限制单个文件不能超过10MB // 确保临时目录存在 try {