Skip to content

Commit 5c98ae2

Browse files
authored
Merge pull request #161 from imagekit-developer/add-checks-parm
Add checks parm
2 parents 0b30679 + 4283090 commit 5c98ae2

File tree

5 files changed

+14
-7
lines changed

5 files changed

+14
-7
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ import { IKImage, IKVideo, IKContext, IKUpload } from 'imagekitio-react'
205205
}
206206
]
207207
}}
208+
checks={`"file.size" < "1mb"`} // To run server side checks before uploading files. Notice the quotes around file.size and 1mb.
208209
/>
209210
</IKContext>
210211
```
@@ -620,12 +621,13 @@ The SDK provides the `IKUpload` component to upload files to the [ImageKit Media
620621
| onUploadStart | Function callback | Optional. Called before the upload is started. The first and only argument is the HTML input's change event |
621622
| onUploadProgress | Function callback | Optional. Called while an upload is in progress. The first and only argument is the ProgressEvent |
622623
| validateFile | Function callback | Optional. This function accepts the `File` object as an argument and exoects a Boolean return value. This is called before the upload is started to run custom validation. The first and only argument is the file selected for upload. If the callback returns `true`, the upload is allowed to continue. But, if it returns `false`, the upload is not done |
623-
| overrideParameters | Function callback | Optional. This function accepts the `File` object as an argument and should return a JSON value, e.g., `{fileName: "new-file-name.jpg"}.` Use this to programmatically override `fileName`, `useUniqueFileName`, `tags`, `folder`, `isPrivateFile`, `customCoordinates`, `extensions`, `webhookUrl`, `overwriteFile`, `overwriteAITags`, `overwriteTags`, `overwriteCustomMetadata`, `customMetadata`, and `transformation` parameters. |
624+
| overrideParameters | Function callback | Optional. This function accepts the `File` object as an argument and should return a JSON value, e.g., `{fileName: "new-file-name.jpg"}.` Use this to programmatically override `fileName`, `useUniqueFileName`, `tags`, `folder`, `isPrivateFile`, `customCoordinates`, `extensions`, `webhookUrl`, `overwriteFile`, `overwriteAITags`, `overwriteTags`, `overwriteCustomMetadata`, `customMetadata`, `transformation`, and `checks` parameters. |
624625
| onSuccess | Function callback | Optional. Called if the upload is successful. The first and only argument is the response JSON from the upload API. The request-id, response headers, and HTTP status code are also accessible using the $ResponseMetadata key that is exposed from the [javascript sdk](https://github.com/imagekit-developer/imagekit-javascript#access-request-id-other-response-headers-and-http-status-code) |
625626
| onError | Function callback | Optional. Called if upload results in an error. The first and only argument is the error received from the upload API |
626627
| urlEndpoint | String | Optional. If not specified, the URL-endpoint specified in the parent `IKContext` component is used. For example, https://ik.imagekit.io/your_imagekit_id/endpoint/ |
627628
| publicKey | String | Optional. If not specified, the `publicKey` specified in the parent `IKContext` component is used. |
628629
| authenticator | ()=>Promise<{signature:string,token:string,expiry:number}> | Optional. If not specified, the `authenticator` specified in the parent `IKContext` component is used. |
630+
| checks | String | Optional. Run server-side checks before uploading files. For example, `"file.size" < "1mb"` will check if the file size is less than 1 MB. Check [Upload API docs](https://imagekit.io/docs/api-reference/upload-file/upload-file#upload-api-checks) to learn more. Notice the quotes around `file.size` and `1mb`; otherwise, you will get an error `Your request contains invalid syntax for the checks parameter.` |
629631

630632

631633
> Make sure that you have specified `authenticator` and `publicKey` in `IKUpload` or in the parent `IKContext` component as a prop. The authenticator expects an asynchronous function that resolves with an object containing the necessary security parameters i.e `signature`, `token`, and `expire`.

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "imagekitio-react",
3-
"version": "4.1.0",
3+
"version": "4.2.0",
44
"description": "React SDK for ImageKit.io which implements client-side upload and URL generation for use inside a react application.",
55
"scripts": {
66
"build:js": "rollup -c",
@@ -80,7 +80,7 @@
8080
"typescript": "^4.8.2"
8181
},
8282
"dependencies": {
83-
"imagekit-javascript": "^3.0.0",
83+
"imagekit-javascript": "^3.0.2",
8484
"prop-types": "^15.7.2"
8585
},
8686
"peerDependencies": {

src/components/IKUpload/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const IKUpload = forwardRef<HTMLInputElement, IKUploadProps & IKContextBaseProps
5050
extensions,
5151
customMetadata,
5252
transformation,
53+
checks,
5354
overrideParameters,
5455
...restProps
5556
} = props;
@@ -151,6 +152,7 @@ const IKUpload = forwardRef<HTMLInputElement, IKUploadProps & IKContextBaseProps
151152
token: '',
152153
xhr,
153154
transformation: overrideValues.transformation || transformation,
155+
checks: overrideValues.checks || checks
154156
};
155157

156158
const authPromise = authenticator();

src/components/IKUpload/props.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const Props = {
7171
ref: PropTypes.any,
7272
transformation: PropTypes.object,
7373
overrideParameters: PropTypes.func,
74+
checks: PropTypes.string
7475
}
7576

7677
export type OverrideValues = {
@@ -88,6 +89,7 @@ export type OverrideValues = {
8889
overwriteCustomMetadata?: IKUploadProps['overwriteCustomMetadata'];
8990
customMetadata?: IKUploadProps['customMetadata'];
9091
transformation?: IKUploadProps['transformation'];
92+
checks?: IKUploadProps['checks'];
9193
};
9294

9395
export type IKUploadProps = Omit<InferProps<typeof Props>, "customMetadata" | "transformation"> & {
@@ -111,6 +113,7 @@ export type IKUploadProps = Omit<InferProps<typeof Props>, "customMetadata" | "t
111113
validateFile?: (file: File) => boolean;
112114
transformation?: TransformationType;
113115
overrideParameters?: (file: File) => OverrideValues;
116+
checks?: string
114117
} & React.InputHTMLAttributes<HTMLInputElement>;
115118

116119
export default Props;

0 commit comments

Comments
 (0)