diff --git a/src/packages/uploader/upload.ts b/src/packages/uploader/upload.ts index 9a19c5e2e0..dd19d49742 100644 --- a/src/packages/uploader/upload.ts +++ b/src/packages/uploader/upload.ts @@ -83,44 +83,40 @@ export class UploaderTaro extends Upload { } uploadTaro(uploadFile: Function, env: string) { const options = this.options - if (env === 'WEB') { - this.upload() + if (options.beforeXhrUpload) { + options.beforeXhrUpload(uploadFile, options) } else { - 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) - }, - }) - options.onStart?.(options) - uploadTask.progress( - (res: { - progress: any - totalBytesSent: any - totalBytesExpectedToSend: any - }) => { - options.onProgress?.(res, options) + 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) + }, + }) + options.onStart?.(options) + uploadTask.progress( + (res: { + progress: any + totalBytesSent: any + totalBytesExpectedToSend: any + }) => { + options.onProgress?.(res, options) + } + ) } } }