import { KVstring } from '.' import { ICustomReqOpts } from './functions' /** * 上传/下载时的原始文件内容。这是编译期开放联合,运行时不按类型拦截: * - Web:`Blob` / `File` / `ArrayBuffer` / TypedArray;`string` 按文件内容上传 * - 小程序:`string` 按本地路径读取,也可传 `ArrayBuffer` / TypedArray * - Node:`Buffer` / `Uint8Array` / `ArrayBuffer` / `Blob`;`string` 按文件内容上传;可读流可带 `size` * * 末尾的 `{ size?: number; byteLength?: number }` 兼容带长度信息的自定义对象。 */ export type FileContent = | Blob | ArrayBuffer | ArrayBufferView | Uint8Array | string | { size?: number; byteLength?: number; [key: string]: any }; export interface ICloudbaseUploadFileParams { cloudPath: string; /** * 上传内容。运行时不按类型拦截: * - Web:`File` / `Blob` / `ArrayBuffer` / TypedArray,或文本;`string` 按内容上传 * - 小程序:本地临时路径(如 `wx.chooseMedia` 的 `tempFilePath`),或 `ArrayBuffer` / TypedArray * - Node:`Buffer` / `Uint8Array` / `ArrayBuffer` / `Blob`、文本,或带 `size` 的可读流 * 与 `fileContent` 同时传入时以本字段为准。 */ filePath?: string | FileContent; /** * 上传方法,默认 `put`。 * @deprecated `'post'` 已废弃,请改用 `'put'`(默认值,可省略本字段)。 */ method?: 'post' | 'put'; headers?: KVstring; onUploadProgress?: Function; /** * `filePath` 的兼容字段,类型与取值规则相同。请改用 `filePath`。 * 两者同时传入时忽略本字段。 */ fileContent?: string | FileContent; customReqOpts?: ICustomReqOpts; } export interface ICloudbaseUploadFileByPutParams { cloudPath: string; /** 与 `ICloudbaseUploadFileParams.filePath` 相同。 */ filePath?: string | FileContent; headers?: KVstring; onUploadProgress?: Function; } export interface ICloudbaseUploadFileResult { fileID: string; requestId: string; } export type ICloudbaseUploadFile = (params: ICloudbaseUploadFileParams, callback?: Function) => Promise; export interface ICloudbaseGetUploadMetadataParams { cloudPath: string; customReqOpts?: ICustomReqOpts; } export type ICloudbaseGetUploadMetadata = (params: ICloudbaseGetUploadMetadataParams, callback?: Function) => Promise; export interface ICloudbaseDeleteFileParams { fileList: string[]; customReqOpts?: ICustomReqOpts; } export type ICloudbaseDeleteFile = (params: ICloudbaseDeleteFileParams, callback?: Function) => Promise; export interface ICloudbaseDeleteFileResult { code?: string; message?: string; fileList?: { code?: string; fileID: string; }[]; requestId?: string; } export interface ICloudbaseFileInfo { fileID: string; /** * 临时下载链接有效期,单位为秒。小于 1 拒绝;大于 3600 时警告后仍按原值下发。 */ maxAge: number; } export interface ICloudbaseGetTempFileURLParams { fileList: string[] | ICloudbaseFileInfo[]; customReqOpts?: ICustomReqOpts; } export interface ICloudbaseGetTempFileURLResult { code?: string; message?: string; fileList?: { code?: string; message?: string; fileID: string; tempFileURL: string; download_url?: string; }[]; requestId?: string; } export interface ICloudbaseCopyFileParams { fileList: Array<{ srcPath: string dstPath: string overwrite?: boolean removeOriginal?: boolean }> customReqOpts?: ICustomReqOpts; } export interface ICloudbaseCopyFileResult { fileList: Array<{ fileId?: string code?: string message?: string }> requestId?: string; } export type ICloudbaseGetTempFileURL = (params: ICloudbaseGetTempFileURLParams, callback?: Function) => Promise; export interface ICloudbaseDownloadFileParams { fileID: string; tempFilePath?: string; customReqOpts?: ICustomReqOpts; } export interface ICloudbaseDownloadFileResult { code?: string; message?: string; /** 下载得到的文件内容:Buffer / 流(Node 端)或 Blob / ArrayBuffer(浏览器端) */ fileContent?: FileContent; requestId?: string; } export type ICloudbaseDownloadFile = (params: ICloudbaseDownloadFileParams, callback?: Function) => Promise; export interface ICloudbaseFileMetaData { url: string; token: string; authorization: string; fileId: string; cosFileId: string; download_url: string; code?: string; message?: string; } export interface ICloudbaseFileMetaDataRes { data: ICloudbaseFileMetaData; requestId: string; }