fix: 添加小程序端不得超过10m的判断,分片信息可以传入upload组件

This commit is contained in:
Pan Qiancheng 2025-12-26 14:09:57 +08:00
parent 10077f150e
commit 336f0b1aa1
5 changed files with 10 additions and 7 deletions

View File

@ -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 ===

View File

@ -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);

View File

@ -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);

View File

@ -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(

View File

@ -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<string[]> {
const fs = wx.getFileSystemManager();
const tempDir = `${wx.env.USER_DATA_PATH}/oak_upload_temp`;
assert(chunkSize <= 10 * 1024 * 1024, '小程序下,单个分片大小不能超过 10MB'); // 微信小程序限制单个文件不能超过10MB
// 确保临时目录存在
try {