UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

46 lines (45 loc) 1.43 kB
import { IUploaderOptions } from './types'; export declare class UploadManager { static uploadManager: UploadManager; static getInstance(): UploadManager; static setConfig(options: IUploaderOptions): void; hash: string; timestamp: number; isRequesting: boolean; options: IUploaderOptions; constructor(); updateHashCode(): Promise<unknown>; requestUpload(file: File): Promise<{ url: string; }>; } /** * 上传文件 * * 上传的本质: * * 1. 小程序上传文件是先用 chooseFile 获取一个文件,可以得到 * 一个临时路径,然后用 uploadFile 上传该临时路径 * * 2. H5 是 input 获取文件,然后用 FormData 上传 File 对象 * @param {File} file 文件 * @returns {Promise<{url: string}>} 上传结果 * * @example * ```ts * import { uploadFile, UploadManager } from 't-comm/lib/uploader' * * uploadFile(file).then(() => {}) * * // 可以通过 UploadManager 设置上传参数 * UploadManager.setConfig({ * requestHashUrl: `https://${location.hostname}/pvp/share/getsharecfg.php`, * uploadFileKey: 'upload_pic_input', * uploadUrlPrefix: 'https://igame.qq.com/external/uploadpic.php?_hash=', * }) * * // 可以通过 UploadManager.getInstance().updateHashCode 主动更新 hashCode * UploadManager.getInstance().updateHashCode(); * ``` */ export declare function uploadFile(file: File): Promise<unknown>;