You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+54-13Lines changed: 54 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,46 @@ ImageKit React SDK allows you to resize, optimize, deliver and upload images and
12
12
13
13
ImageKit is a complete media storage, optimization, and transformation solution that comes with an image and video CDN. It can be integrated with your existing infrastructure - storage like AWS S3, web servers, your CDN, and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes.
14
14
15
+
## Changelog - SDK Version 3.0.0
16
+
### Breaking changes
17
+
**1. Authentication Process Update:**
18
+
* Previously, when using this SDK, we had to pass `authenticationEndpoint` which is used by SDK internally for fetching security parameters i.e `signature`, `token`, and `expire`.
19
+
* In version 3.0.0, we have deprecated the use of the `authenticationEndpoint` parameter. Instead, the SDK now introduces a new parameter named `authenticator`. This parameter expects an asynchronous function that resolves with an object containing the necessary security parameters i.e `signature`, `token`, and `expire`.
20
+
* Now `ref` needs to passed instead of `inputRef` in IKUpload component
21
+
22
+
Example implementation for `authenticator` using `Fetch API`.
23
+
24
+
```javascript
25
+
26
+
constauthenticator=async () => {
27
+
try {
28
+
29
+
// You can pass headers as well and later validate the request source in the backend, or you can use headers for any other use case.
30
+
constheaders= {
31
+
'Authorization':'Bearer your-access-token',
32
+
'CustomHeader':'CustomValue'
33
+
};
34
+
35
+
constresponse=awaitfetch('server_endpoint', {
36
+
headers
37
+
});
38
+
39
+
if (!response.ok) {
40
+
consterrorText=awaitresponse.text();
41
+
thrownewError(`Request failed with status ${response.status}: ${errorText}`);
*Note*: Avoid generating security parameters on the client side. Always send a request to your backend to retrieve security parameters, as the generation of these parameters necessitates the use of your Imagekit `privateKey`, which must not be included in client-side code.
*[`IKContext`](#IKContext) for defining options like `urlEndpoint`, `publicKey` or `authenticationEndpoint` to all children elements. This component does not render anything.
187
+
*[`IKContext`](#IKContext) for defining options like `urlEndpoint`, `publicKey` or `authenticator` to all children elements. This component does not render anything.
148
188
*`IKImage` for [image resizing](#image-resizing). This renders a `<img>` tag.
149
189
*`IKVideo` for [video resizing](#video-resizing). This renders a `<video>` tag.
150
190
*`IKUpload`for client-side [file uploading](#file-upload). This renders a `<input type="file">` tag.
@@ -159,7 +199,7 @@ To use this SDK, you need to provide it with a few configuration parameters. You
159
199
urlEndpoint="https://ik.imagekit.io/your_imagekit_id"// Required. Default URL-endpoint is https://ik.imagekit.io/your_imagekit_id
*`urlEndpoint` is required to use the SDK. You can get URL-endpoint from your ImageKit dashboard - https://imagekit.io/dashboard/url-endpoints.
174
-
*`publicKey` and `authenticationEndpoint` parameters are required if you want to use the SDK for client-side file upload. You can get these parameters from the developer section in your ImageKit dashboard - https://imagekit.io/dashboard/developer/api-keys.
214
+
*`publicKey` and `authenticator` parameters are required if you want to use the SDK for client-side file upload. You can get these parameters from the developer section in your ImageKit dashboard - https://imagekit.io/dashboard/developer/api-keys.
175
215
*`transformationPosition` is optional. The default value for this parameter is `path`. Acceptable values are `path` & `query`
176
216
177
217
> Note: Do not include your [private key](https://docs.imagekit.io/api-reference/api-introduction/api-keys#private-key) in any client-side code.
@@ -491,17 +531,17 @@ The SDK provides the `IKUpload` component to upload files to the [ImageKit Media
491
531
| overwriteAITags | Boolean | Optional. 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. |
492
532
| overwriteCustomMetadata | Boolean | Optional. 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. |
493
533
| customMetadata | Object | Optional. JSON key-value data to be associated with the asset. |
494
-
|inputRef| Reference | Optional. Forward reference to the core HTMLInputElement.|
534
+
|ref| Reference | Optional. Forward reference to the core HTMLInputElement.|
495
535
| onUploadStart | Function callback | Optional. Called before the upload is started. The first and only argument is the HTML input's change event |
496
536
| onUploadProgress | Function callback | Optional. Called while an upload is in progress. The first and only argument is the ProgressEvent |
497
537
| validateFile | Function callback | Optional. 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 |
498
538
| 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)|
499
539
| onError | Function callback | Optional. Called if upload results in an error. The first and only argument is the error received from the upload API |
500
540
| 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/|
501
541
| publicKey | String | Optional. If not specified, the `publicKey` specified in the parent `IKContext` component is used.|
502
-
|authenticationEndpoint|String| Optional. If not specified, the `authenticationEndpoint` specified in the parent `IKContext` component is used. |
542
+
|authenticator|()=>Promise<{signature:string,token:string,expiry:number}>| Optional. If not specified, the `authenticator` specified in the parent `IKContext` component is used. |
503
543
504
-
> Make sure that you have specified `authenticationEndpoint` and `publicKey` in `IKUpload` or in the parent `IKContext` component as a prop. The SDK makes an HTTP GET request to this endpoint and expects a JSON response with three fields i.e.`signature`, `token`, and `expire`. [Learn how to implement authenticationEndpoint](https://docs.imagekit.io/api-reference/upload-file-api/client-side-file-upload#how-to-implement-authenticationendpoint-endpoint) on your server. Refer to [demo application](#demo-application) for an example implementation.
544
+
> 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`.
0 commit comments