import Vnmf from '../../index' declare module '../../index' { namespace uploadFile { interface Option { /** Developer Server Address */ url: string /** Path to upload file resources */ filePath: string /** The file corresponds to the file. key,Developer can get through this on the server. key Binary content to fetch files */ name: string /** HTTP Request Header,Header Could not close temporary folder: %s Referer */ header?: VnmfGeneral.IAnyObject /** HTTP Other additional requests form data */ formData?: VnmfGeneral.IAnyObject /** Timeout,in milliseconds */ timeout?: number /** Uploading filenames * @supported h5 */ fileName?: string /** Interface call to the end of echo function(Call successfully、Any failure will be enforced.) */ complete?: (res: VnmfGeneral.CallbackResult) => void /** Interface call failed echo function */ fail?: (res: VnmfGeneral.CallbackResult) => void /** Interface calls a successful echo function */ success?: ( result: SuccessCallbackResult, ) => void } interface SuccessCallbackResult extends VnmfGeneral.CallbackResult { /** Data returned by Developer Server */ data: string /** Backed by Developer Server HTTP Status Code */ statusCode: number /** Call Results */ errMsg: string /** * Backed by Developer Server HTTP Response Header * @supported weapp * @weapp Unofficial document labelling properties */ header?: VnmfGeneral.IAnyObject /** * cookies * @supported weapp * @weapp Unofficial document labelling properties */ cookies?: string[] } } namespace UploadTask { /** HTTP Response Header Event echo function */ type OffHeadersReceivedCallback = ( res: VnmfGeneral.CallbackResult, ) => void /** Upload progress change event echo function */ type OffProgressUpdateCallback = ( res: VnmfGeneral.CallbackResult, ) => void /** HTTP Response Header Event echo function */ type OnHeadersReceivedCallback = ( result: OnHeadersReceivedCallbackResult, ) => void /** Upload progress change event echo function */ type OnProgressUpdateCallback = ( result: OnProgressUpdateCallbackResult, ) => void interface OnHeadersReceivedCallbackResult { /** Backed by Developer Server HTTP Response Header */ header: VnmfGeneral.IAnyObject } interface OnProgressUpdateCallbackResult { /** % Upload Progress */ progress: number /** Total expected length of data to be uploaded,Units Bytes */ totalBytesExpectedToSend: number /** Length of data uploaded,Units Bytes */ totalBytesSent: number } type UploadTaskPromise = Promise & UploadTask & { headersReceive: UploadTask['onHeadersReceived'], progress: UploadTask['onProgressUpdate'] } } /** An event that can listen to upload progress changes.,And the object that canceled upload. * @supported weapp, swan, alipay, h5, rn, tt * @example * ```tsx * const uploadTask = Vnmf.uploadFile({ * url: 'http://example.weixin.qq.com/upload', //Example:,Unreal interface address * filePath: tempFilePaths[0], * name: 'file', * formData:{ * 'user': 'test' * }, * success (res){ * const data = res.data * //do something * } * }) * * uploadTask.onProgressUpdate((res) => { * console.log('Upload Progress', res.progress) * console.log('Length of data uploaded', res.totalBytesSent) * console.log('Total expected length of data to be uploaded', res.totalBytesExpectedToSend) * }) * * uploadTask.abort() // Could not close temporary folder: %s * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/UploadTask.html */ interface UploadTask { /** Interrupt Uploading Tasks * @supported weapp, h5, tt * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/UploadTask.abort.html */ abort(): void /** Listen to Upload Progress Changes * @supported weapp, h5, tt * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/UploadTask.onProgressUpdate.html */ onProgressUpdate( /** Upload progress change event echo function */ callback: UploadTask.OnProgressUpdateCallback, ): void /** Disable listening to upload progress changes * @supported weapp, h5, tt * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/UploadTask.offProgressUpdate.html */ offProgressUpdate( /** Upload progress change event echo function */ callback: UploadTask.OffProgressUpdateCallback, ): void /** Listening. HTTP Response Header Events。It'll be sooner than requesting the completion of incident. * @supported weapp, h5 * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/UploadTask.onHeadersReceived.html */ onHeadersReceived( /** HTTP Response Header Event echo function */ callback: UploadTask.OnHeadersReceivedCallback, ): void /** Disable listening. HTTP Response Header Events * @supported weapp, h5 * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/UploadTask.offHeadersReceived.html */ offHeadersReceived( /** HTTP Response Header Event echo function */ callback: UploadTask.OffHeadersReceivedCallback, ): void } interface VnmfStatic { /** Uploading local resources to a server。Client Launch One HTTPS POST Request,of which `content-type` Yes. `multipart/form-data`。Read carefully before using[Relevant notes](https://developers.weixin.qq.com/miniprogram/dev/framework/ability/network.html)。 * @supported weapp, swan, alipay, h5, rn, tt * @example * ```tsx * Vnmf.chooseImage({ * success (res) { * const tempFilePaths = res.tempFilePaths * Vnmf.uploadFile({ * url: 'https://example.weixin.qq.com/upload', //Example:,Unreal interface address * filePath: tempFilePaths[0], * name: 'file', * formData: { * 'user': 'test' * }, * success (res){ * const data = res.data * //do something * } * }) * } * }) * ``` * @example * ```tsx * const uploadTask = Vnmf.uploadFile({ * url: 'https://example.weixin.qq.com/upload', //Example:,Unreal interface address * filePath: tempFilePaths[0], * name: 'file', * formData:{ * 'user': 'test' * }, * success: function (res){ * var data = res.data * //do something * } * }) * uploadTask.progress((res) => { * console.log('Upload Progress', res.progress) * console.log('Length of data uploaded', res.totalBytesSent) * console.log('Total expected length of data to be uploaded', res.totalBytesExpectedToSend) * }) * uploadTask.abort() // Could not close temporary folder: %s * ``` * @see https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/wx.uploadFile.html */ uploadFile(option: uploadFile.Option): UploadTask.UploadTaskPromise } }