UNPKG

2.84 kBTypeScriptView Raw
1import { RequestResult, UploadProgressEvent } from "./utils/request";
2declare type Region = 'oss-cn-hangzhou' | 'oss-cn-shanghai' | 'oss-cn-qingdao' | 'oss-cn-beijing' | 'oss-cn-zhangjiakou' | 'oss-cn-huhehaote' | 'oss-cn-shenzhen' | 'oss-cn-heyuan' | 'oss-cn-chengdu' | 'oss-cn-hongkong' | 'oss-us-west-1' | 'oss-us-east-1' | 'oss-ap-southeast-1' | 'oss-ap-southeast-2' | 'oss-ap-southeast-3' | 'oss-ap-southeast-5' | 'oss-ap-northeast-1' | 'oss-ap-south-1' | 'oss-eu-central-1' | 'oss-eu-west-1' | 'oss-me-east-1' | string;
3export interface ClientOptions {
4 /**
5 * access key you create on aliyun console website
6 */
7 accessKeyId: string;
8 /**
9 * access secret you create
10 */
11 accessKeySecret: string;
12 bucket?: string;
13 /**
14 * used by temporary authorization
15 */
16 stsToken?: string;
17 /**
18 * oss region domain. It takes priority over `region`
19 */
20 endpoint?: string;
21 /**
22 * the bucket data region location, default is `oss-cn-hangzhou`
23 */
24 region?: Region;
25 /**
26 * access OSS with aliyun internal network or not, default is false. If your servers are running on aliyun too,
27 * you can set true to save lot of money.
28 */
29 internal?: boolean;
30 /**
31 * instance level timeout for all operations, default is 60_000(60s).
32 */
33 timeout?: number;
34 secure?: boolean;
35 /**
36 * default false, access oss with custom domain name. if true, you can fill endpoint field with your custom domain name
37 */
38 cname?: boolean;
39}
40export interface PostObjectOptions {
41 dir?: string;
42 policy?: string | {
43 expiration: string;
44 conditions: any[];
45 };
46 signature?: string;
47 timeout?: number;
48 onProgress?: (e: UploadProgressEvent) => void;
49 onSuccess?: (result: RequestResult, xhr: XMLHttpRequest) => void;
50 onError?: (e: Error) => void;
51 onAbort?: () => void;
52 success_action_status?: 200 | 201 | 204;
53 success_action_redirect?: string;
54 'x-oss-object-acl'?: 'private' | 'public-read' | 'public-read-write';
55 headers?: {
56 [key: string]: string | number;
57 };
58 [key: string]: any;
59}
60declare class Client {
61 protected opts: ClientOptions & {
62 host: string;
63 };
64 constructor(options: ClientOptions);
65 /**
66 * post object as form/multi-part
67 * @param name
68 * @param file
69 * @param options
70 */
71 postObject(name: string, file: File | Blob, options?: PostObjectOptions): {
72 abort(): void;
73 };
74 /**
75 * Get the Object url.
76 * If provide baseUrl, will use baseUrl instead the default bucket and endpoint .
77 * @param name
78 * @param baseUrl
79 */
80 generateObjectUrl(name: string, baseUrl?: string): string;
81}
82export default Client;