|
|
@@ -314,11 +314,13 @@ export class MinIOXHRUploader {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-export async function getUploadPolicy(key: string, fileName: string): Promise<MinioUploadPolicy> {
|
|
|
+export async function getUploadPolicy(key: string, fileName: string, fileType?: string, fileSize?: number): Promise<MinioUploadPolicy> {
|
|
|
const policyResponse = await fileClient["upload-policy"].$post({
|
|
|
json: {
|
|
|
path: key,
|
|
|
- name: fileName
|
|
|
+ name: fileName,
|
|
|
+ type: fileType,
|
|
|
+ size: fileSize
|
|
|
}
|
|
|
});
|
|
|
if (!policyResponse.ok) {
|
|
|
@@ -327,9 +329,14 @@ export async function getUploadPolicy(key: string, fileName: string): Promise<Mi
|
|
|
return policyResponse.json();
|
|
|
}
|
|
|
|
|
|
-export async function getMultipartUploadPolicy(totalSize: number,fileKey: string) {
|
|
|
+export async function getMultipartUploadPolicy(totalSize: number, fileKey: string, fileType?: string) {
|
|
|
const policyResponse = await fileClient["multipart-policy"].$post({
|
|
|
- json: { totalSize, partSize: PART_SIZE, fileKey}
|
|
|
+ json: {
|
|
|
+ totalSize,
|
|
|
+ partSize: PART_SIZE,
|
|
|
+ fileKey,
|
|
|
+ type: fileType
|
|
|
+ }
|
|
|
});
|
|
|
if (!policyResponse.ok) {
|
|
|
throw new Error('获取分段上传策略失败');
|
|
|
@@ -352,7 +359,7 @@ export async function uploadMinIOWithPolicy(
|
|
|
|
|
|
|
|
|
if( file.size > PART_SIZE ){
|
|
|
- const policy = await getMultipartUploadPolicy(file.size, `${uploadPath}${fileKey}`)
|
|
|
+ const policy = await getMultipartUploadPolicy(file.size, `${uploadPath}${fileKey}`, file instanceof File ? file.type : undefined)
|
|
|
return MinIOXHRMultipartUploader.upload(
|
|
|
policy,
|
|
|
file,
|
|
|
@@ -363,7 +370,7 @@ export async function uploadMinIOWithPolicy(
|
|
|
if (!(file instanceof File)) {
|
|
|
throw new Error('不支持的文件类型,无法获取文件名');
|
|
|
}
|
|
|
- const policy = await getUploadPolicy(`${uploadPath}${fileKey}`, file.name);
|
|
|
+ const policy = await getUploadPolicy(`${uploadPath}${fileKey}`, file.name, file.type, file.size);
|
|
|
return MinIOXHRUploader.upload(policy, file, policy.uploadPolicy.key, callbacks);
|
|
|
}
|
|
|
}
|