更新版本至 0.0.38,修复文件上传时的 chunk 参数设置,优化文件切片处理
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@kevisual/api",
|
||||
"version": "0.0.37",
|
||||
"version": "0.0.38",
|
||||
"description": "",
|
||||
"main": "mod.ts",
|
||||
"scripts": {
|
||||
|
||||
@@ -107,7 +107,7 @@ export class QueryResources {
|
||||
const filename = path.basename(pathname);
|
||||
const url = new URL(pathname, window.location.origin);
|
||||
url.searchParams.set('hash', hash);
|
||||
url.searchParams.set('chunked', '1');
|
||||
url.searchParams.set('chunk', '1');
|
||||
console.log(`url,`, url, hash);
|
||||
// 预留 eventSource 支持(暂不处理)
|
||||
// const createEventSource = opts?.createEventSource;
|
||||
@@ -118,10 +118,12 @@ export class QueryResources {
|
||||
for (let currentChunk = 0; currentChunk < totalChunks; currentChunk++) {
|
||||
const start = currentChunk * chunkSize;
|
||||
const end = Math.min(start + chunkSize, file.size);
|
||||
const chunk = file.slice(start, end);
|
||||
const chunkBlob = file.slice(start, end);
|
||||
// 转换为 File 类型
|
||||
const chunkFile = new File([chunkBlob], filename, { type: file.type || 'application/octet-stream' });
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('file', chunk, filename);
|
||||
formData.append('file', chunkFile, filename);
|
||||
formData.append('chunkIndex', currentChunk.toString());
|
||||
formData.append('totalChunks', totalChunks.toString());
|
||||
console.log(`Uploading chunk ${currentChunk + 1}/${totalChunks}`, url.toString());
|
||||
@@ -136,6 +138,7 @@ export class QueryResources {
|
||||
headers: { ...opts?.headers, ...this.header(opts?.headers, false) },
|
||||
params: {
|
||||
hash: hash,
|
||||
chunk: '1',
|
||||
...opts?.params,
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user