-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathUploadOptions.ts
More file actions
169 lines (154 loc) · 7.29 KB
/
UploadOptions.ts
File metadata and controls
169 lines (154 loc) · 7.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
interface TransformationObject {
type: "transformation";
value: string;
}
interface GifToVideoOrThumbnailObject {
type: "gif-to-video" | "thumbnail";
value?: string;
}
interface AbsObject {
type: "abs";
value: string;
protocol: "hls" | "dash";
}
type PostTransformation = TransformationObject | GifToVideoOrThumbnailObject | AbsObject;
interface Transformation {
pre?: string
post?: PostTransformation[]
}
/**
* Options used when uploading a file
*
* {@link https://imagekit.io/docs/api-reference/upload-file/upload-file#Request}
*/
export interface UploadOptions {
/**
* This field accepts three kinds of values:
* - binary - You can send the content of the file as binary. This is used when a file is being uploaded from the browser.
* - base64 - Base64 encoded string of file content.
* - url - URL of the file from where to download the content before uploading.
* Downloading file from URL might take longer, so it is recommended that you pass the binary or base64 content of the file.
* Pass the full URL, for example - https://www.example.com/rest-of-the-image-path.jpg.
*/
file: string | Blob | File;
/**
* The name with which the file has to be uploaded.
* The file name can contain:
* - Alphanumeric Characters: a-z , A-Z , 0-9 (including unicode letters, marks, and numerals in other languages)
* - Special Characters: . _ and -
* Any other character including space will be replaced by _
*/
fileName: string;
/**
* HMAC-SHA1 digest of the token+expire using your ImageKit.io private API key as a key. This should be in lowercase.
* Warning: Signature must be calculated on the server-side. This field is required for authentication when uploading a file from the client-side.
*/
signature: string;
/**
* A unique value generated by the client, which will be used by the ImageKit.io server to recognize and prevent subsequent retries for the same request. We suggest using V4 UUIDs, or another random string with enough entropy to avoid collisions.
* Note: Sending a value that has been used in the past will result in a validation error. Even if your previous request resulted in an error, you should always send a new value for this field.
*/
token: string;
/**
* The time until your signature is valid. It must be a Unix time in less than 1 hour into the future. It should be in seconds.
*/
expire: number;
/**
* The public API key of your ImageKit account. You can find it in the [ImageKit dashboard](https://imagekit.io/dashboard/developer/api-keys).
*/
publicKey: string;
/**
* Whether to use a unique filename for this file or not.
* - Accepts true or false.
* - If set true, ImageKit.io will add a unique suffix to the filename parameter to get a unique filename.
* - If set false, then the image is uploaded with the provided filename parameter and any existing file with the same name is replaced.
* Default value - true
*/
useUniqueFileName?: boolean;
/**
* Set the tags while uploading the file.
* - Comma-separated value of tags in format tag1,tag2,tag3. For example - t-shirt,round-neck,men
* - The maximum length of all characters should not exceed 500.
* - % is not allowed.
* - If this field is not specified and the file is overwritten then the tags will be removed.
*/
tags?: string | string[];
/**
* The folder path (e.g. /images/folder/) in which the image has to be uploaded. If the folder(s) didn't exist before, a new folder(s) is created.
* The folder name can contain:
* - Alphanumeric Characters: a-z , A-Z , 0-9 (including unicode letters, marks, and numerals in other languages)
* - Special Characters: / _ and -
* - Using multiple / creates a nested folder.
* Default value - /
*/
folder?: string;
/**
* Whether to mark the file as private or not. This is only relevant for image type files.
* - Accepts true or false.
* - If set true, the file is marked as private which restricts access to the original image URL and unnamed image transformations without signed URLs.
* Without the signed URL, only named transformations work on private images
* Default value - false
*/
isPrivateFile?: boolean;
/**
* Define an important area in the image. This is only relevant for image type files.
* To be passed as a string with the x and y coordinates of the top-left corner, and width and height of the area of interest in format x,y,width,height. For example - 10,10,100,100
* Can be used with fo-customtransformation.
* If this field is not specified and the file is overwritten, then customCoordinates will be removed.
*/
customCoordinates?: string;
/**
* Comma-separated values of the fields that you want ImageKit.io to return in response.
*
* For example, set the value of this field to tags,customCoordinates,isPrivateFile,metadata to get value of tags, customCoordinates, isPrivateFile , and metadata in the response.
*/
responseFields?: string | string[];
/*
* Object with array of extensions to be processed on the image.
*/
extensions?: object[];
/*
* Final status of pending extensions will be sent to this URL.
*/
webhookUrl?: string
/*
* Default is true. If overwriteFile is set to false and useUniqueFileName is also false, and a file already exists at the exact location, upload API will return an error immediately.
*/
overwriteFile?: boolean
/*
* Default is true. If set to true and a file already exists at the exact location, its AITags will be removed. Set overwriteAITags to false to preserve AITags.
*/
overwriteAITags?: boolean
/*
* Default is true. If the request does not have tags , overwriteTags is set to true and a file already exists at the exact location, existing tags will be removed.
* In case the request body has tags, setting overwriteTags to false has no effect and request's tags are set on the asset.
*/
overwriteTags?: boolean
/*
* Default is true. If the request does not have customMetadata , overwriteCustomMetadata is set to true and a file already exists at the exact location, exiting customMetadata will be removed.
* In case the request body has customMetadata, setting overwriteCustomMetadata to false has no effect and request's customMetadata is set on the asset.
*/
overwriteCustomMetadata?: boolean
/*
* Stringified JSON key-value data to be associated with the asset. Checkout overwriteCustomMetadata parameter to understand default behaviour.
* Before setting any custom metadata on an asset you have to create the field using custom metadata fields API.
*/
customMetadata?: string | Record<string, string | number | boolean | Array<string | number | boolean>>
transformation?: Transformation
/**
* Optional XMLHttpRequest object that you can send for upload API request. You can listen to `progress` and other events on this object for any custom logic.
*/
xhr?: XMLHttpRequest
/**
* Optional `checks` parameters can be used to run server-side checks before files are uploaded to the Media Library.
*/
checks?: string;
/**
* Optional callback function that will be called with the progress event when the file is being uploaded.
*/
onProgress?: (event: ProgressEvent) => void;
/**
* Optional AbortSignal object that can be used to abort the upload request
*/
signal?: AbortSignal;
}