|
@@ -63,36 +63,39 @@ export class Uploader {
|
|
|
if (env === 'WEB') {
|
|
if (env === 'WEB') {
|
|
|
this.upload();
|
|
this.upload();
|
|
|
} else {
|
|
} else {
|
|
|
- const uploadTask = uploadFile({
|
|
|
|
|
- url: options.url,
|
|
|
|
|
- filePath: options.taroFilePath,
|
|
|
|
|
- fileType: options.fileType,
|
|
|
|
|
- header: {
|
|
|
|
|
- 'Content-Type': 'multipart/form-data',
|
|
|
|
|
- ...options.headers
|
|
|
|
|
- }, //
|
|
|
|
|
- formData: options.formData,
|
|
|
|
|
- name: options.name,
|
|
|
|
|
- success(response: { errMsg: any; statusCode: number; data: string }) {
|
|
|
|
|
- if (options.xhrState == response.statusCode) {
|
|
|
|
|
- options.onSuccess?.(response, options);
|
|
|
|
|
- } else {
|
|
|
|
|
- options.onFailure?.(response, options);
|
|
|
|
|
|
|
+ if (options.beforeXhrUpload) {
|
|
|
|
|
+ options.beforeXhrUpload(uploadFile, options);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ const uploadTask = uploadFile({
|
|
|
|
|
+ url: options.url,
|
|
|
|
|
+ filePath: options.taroFilePath,
|
|
|
|
|
+ fileType: options.fileType,
|
|
|
|
|
+ header: {
|
|
|
|
|
+ 'Content-Type': 'multipart/form-data',
|
|
|
|
|
+ ...options.headers
|
|
|
|
|
+ }, //
|
|
|
|
|
+ formData: options.formData,
|
|
|
|
|
+ name: options.name,
|
|
|
|
|
+ success(response: { errMsg: any; statusCode: number; data: string }) {
|
|
|
|
|
+ if (options.xhrState == response.statusCode) {
|
|
|
|
|
+ options.onSuccess?.(response, options);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ options.onFailure?.(response, options);
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ fail(e: any) {
|
|
|
|
|
+ options.onFailure?.(e, options);
|
|
|
}
|
|
}
|
|
|
- },
|
|
|
|
|
- fail(e: any) {
|
|
|
|
|
- options.onFailure?.(e, options);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- options.onStart?.(options);
|
|
|
|
|
- uploadTask.progress((res: { progress: any; totalBytesSent: any; totalBytesExpectedToSend: any }) => {
|
|
|
|
|
- options.onProgress?.(res, options);
|
|
|
|
|
- // console.log('上传进度', res.progress);
|
|
|
|
|
- // console.log('已经上传的数据长度', res.totalBytesSent);
|
|
|
|
|
- // console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // uploadTask.abort(); // 取消上传任务
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ options.onStart?.(options);
|
|
|
|
|
+ uploadTask.progress((res: { progress: any; totalBytesSent: any; totalBytesExpectedToSend: any }) => {
|
|
|
|
|
+ options.onProgress?.(res, options);
|
|
|
|
|
+ // console.log('上传进度', res.progress);
|
|
|
|
|
+ // console.log('已经上传的数据长度', res.totalBytesSent);
|
|
|
|
|
+ // console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend);
|
|
|
|
|
+ });
|
|
|
|
|
+ // uploadTask.abort(); // 取消上传任务
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|