|
5 | 5 | [](https://opensource.org/licenses/MIT)
|
6 | 6 | [](https://twitter.com/ImagekitIo)
|
7 | 7 |
|
8 |
| -Vue SDK for [ImageKit.io](https://imagekit.io) which implements client-side upload and URL generation for use inside a vue application. |
| 8 | +Vue SDK for [ImageKit.io](https://imagekit.io), which implements client-side upload and URL generation for use inside a vue application. |
9 | 9 |
|
10 |
| -ImageKit is a complete image optimization and transformation solution that comes with an [image CDN](https://imagekit.io/features/imagekit-infrastructure) and media storage. It can be integrated with your existing infrastructure - storages like AWS S3, web servers, your CDN and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes. |
| 10 | +ImageKit is a complete image optimization and transformation solution that comes with an [image CDN](https://imagekit.io/features/imagekit-infrastructure) and media storage. 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. |
11 | 11 |
|
12 | 12 | ## Installation
|
13 | 13 |
|
14 |
| - `npm install --save imagekitio-vue` |
| 14 | +`npm install --save imagekitio-vue` |
15 | 15 |
|
16 | 16 | Include the components in your code:
|
17 | 17 |
|
18 |
| - `import {IKContext} from "imagekitio-vue"` |
| 18 | +`import {IKContext} from "imagekitio-vue"` |
19 | 19 |
|
20 | 20 | ## Usage
|
21 | 21 |
|
22 | 22 | The library includes 3 Components:
|
23 | 23 | * [IKContext](#IKContext)
|
24 | 24 |
|
25 |
| -* [IKImage](#IKImage) |
| 25 | +* [IKImage - URL generation](#ikimage---url-generation) |
26 | 26 |
|
27 |
| -* [IKUpload](#file-upload) |
| 27 | +* [IKUpload - File upload](#ikupload---file-upload) |
28 | 28 |
|
29 | 29 | ### IKContext
|
30 | 30 |
|
31 | 31 | In order to use the SDK, you need to provide it with a few configuration parameters. The configuration parameters can be applied directly to the `Image` component or using an `IKContext` component. example:
|
32 | 32 |
|
33 | 33 | ```js
|
34 |
| - template: <IKContext publicKey="your_public_api_key" urlEndpoint="<https://ik.imagekit.io/your_imagekit_id>"><IKImage src="<full_image_url_from_db>"/></IKContext> |
| 34 | +<IKContext |
| 35 | + publicKey="your_public_api_key" |
| 36 | + urlEndpoint="<https://ik.imagekit.io/your_imagekit_id>"> |
| 37 | + <IKImage src="<full_image_url_from_db>"/> |
| 38 | +</IKContext> |
35 | 39 | ```
|
36 | 40 |
|
37 | 41 | `publicKey` and `urlEndpoint` are mandatory parameters for SDK initialization.
|
38 | 42 | `authenticationEndpoint` is essential if you want to use the SDK for client-side uploads.
|
39 |
| -`transformationPosition` is optional. The default value for the parametere is `path`. Acceptable values are `path` & `query` |
| 43 | +`transformationPosition` is optional. The default value for this parameter is `path`. Acceptable values are `path` & `query` |
40 | 44 |
|
41 |
| -_Note: Do not include your Private Key in any client side code, including this SDK or its initialization. If you pass the `privateKey` parameter while initializing this SDK, it throws an error_ |
| 45 | +_Note: Do not include your Private Key in any client-side code, including this SDK or its initialization. If you pass the `privateKey` parameter while initializing this SDK, it throws an error_ |
42 | 46 |
|
43 |
| -### IKImage |
| 47 | +### IKImage - URL generation |
44 | 48 |
|
45 |
| -The image component component defines a ImageKit Image tag. example usage: |
| 49 | +The image component defines an IKImage tag. Example usage: |
46 | 50 |
|
47 | 51 | #### Using image path and image hostname or endpoint
|
48 | 52 |
|
49 | 53 | ```js
|
50 |
| - template: '<IKImage publicKey="your_public_api_key" urlEndpoint="https://ik.imagekit.io/your_imagekit_id" path="/path_to_file"/>' |
| 54 | +<IKImage |
| 55 | + publicKey="your_public_api_key" |
| 56 | + urlEndpoint="https://ik.imagekit.io/your_imagekit_id" |
| 57 | + path="/path_to_file"/> |
| 58 | +``` |
51 | 59 |
|
52 |
| - ``` |
53 | 60 | #### Using full image URL
|
54 | 61 |
|
55 |
| - ```js |
56 |
| - template: '<IKImage publicKey="your_public_api_key" urlEndpoint="https://ik.imagekit.io/your_imagekit_id" src="<full_image_url_from_db>"/>' |
57 |
| - ``` |
58 |
| - |
59 |
| -`src` is the complete URL that is already mapped to ImageKit. |
60 |
| -`path` is the location of the image in the ImageKit cloud. `urlEndpoint` + `path` makes the complete url. |
61 |
| -`transformations` is optional. The transformations to be applied to a given image. It is declared in the form of an array of objects, where each object specifies the transformation you need. The values are mentioned below. |
| 62 | +```js |
| 63 | +<IKImage |
| 64 | + publicKey="your_public_api_key" |
| 65 | + urlEndpoint="https://ik.imagekit.io/your_imagekit_id" |
| 66 | + src="<full_image_url_from_db>"/>' |
| 67 | +``` |
| 68 | +
|
| 69 | +#### Supported options: |
| 70 | +
|
| 71 | +| Option | Description | |
| 72 | +| :----------------| :----------------------------- | |
| 73 | +| urlEndpoint | Optional. The base URL to be appended before the path of the image. If not specified, the URL Endpoint specified at the time of SDK initialization is used. For example, https://ik.imagekit.io/your_imagekit_id/endpoint/ | |
| 74 | +| path | Conditional. This is the path at which the image exists. For example, `/path/to/image.jpg`. Either the `path` or `src` parameter need to be specified for URL generation. | |
| 75 | +| src | Conditional. This is the complete URL of an image already mapped to ImageKit. For example, `https://ik.imagekit.io/your_imagekit_id/endpoint/path/to/image.jpg`. Either the `path` or `src` parameter need to be specified for URL generation. | |
| 76 | +| transformation | Optional. An array of objects specifying the transformation to be applied in the URL. The transformation name and the value should be specified as a key-value pair in the object. Different steps of a [chained transformation](https://docs.imagekit.io/features/image-transformations/chained-transformations) can be specified as different objects of the array. The complete list of supported transformations in the SDK and some examples of using them are given later. If you use a transformation name that is not specified in the SDK, it gets applied as it is in the URL. | |
| 77 | +| transformationPostion | Optional. The default value is `path` that places the transformation string as a path parameter in the URL. It can also be specified as `query` which adds the transformation string as the query parameter `tr` in the URL. If you use `src` parameter to create the URL, then the transformation string is always added as a query parameter. | |
| 78 | +| queryParameters | Optional. These are the other query parameters that you want to add to the final URL. These can be any query parameters and not necessarily related to ImageKit. Especially useful if you want to add some versioning parameter to your URLs. | |
| 79 | +
|
62 | 80 |
|
63 | 81 | #### List of supported transformations
|
64 | 82 |
|
65 |
| -The complete list of transformations supported and their usage in ImageKit can be found [here](https://docs.imagekit.io/imagekit-docs/image-transformations). The SDK gives a name to each transformation parameter, making the code simpler and readable. If a transformation is supported in ImageKit, but a name for it cannot be found in the table below, then use the transformation code from ImageKit docs as the name when using in the `url` function. |
| 83 | +The complete list of transformations supported and their usage in ImageKit can be found [here](https://docs.imagekit.io/features/image-transformations). The SDK gives a name to each transformation parameter, making the code simpler and readable. If a transformation is supported in ImageKit, but a name for it cannot be found in the table below, then use the transformation code from ImageKit docs as the name when using in the `url` function. |
66 | 84 |
|
67 | 85 | | Supported Transformation Name | Translates to parameter |
|
68 | 86 | | ----------------------------- | ----------------------- |
|
@@ -112,42 +130,87 @@ The complete list of transformations supported and their usage in ImageKit can b
|
112 | 130 | #### Applying Transforms
|
113 | 131 | ```js
|
114 | 132 |
|
115 |
| -template: '<IKImage publicKey="your_public_api_key" urlEndpoint="https://ik.imagekit.io/gqyojxcwzxj/" src="<full_image_url_from_db>" v-bind:transformation="[{height:300,width:400}]" />' |
| 133 | +<IKImage |
| 134 | + publicKey="your_public_api_key" |
| 135 | + urlEndpoint="https://ik.imagekit.io/gqyojxcwzxj/" |
| 136 | + src="<full_image_url_from_db>" |
| 137 | + v-bind:transformation="[{height:300,width:400}]" /> |
116 | 138 | ```
|
117 | 139 | The above image will apply transformation of width = 90 and height = 180 on the image. Since some transformatinos are destructive you might want to control the order in which the transforms are applied.
|
118 | 140 |
|
119 | 141 | ##### Chained Transforms
|
120 | 142 | Chained transforms make it easy to specify the order the transform are applied. example:
|
121 | 143 |
|
122 | 144 | ```js
|
123 |
| -template: '<IKImage publicKey="your_public_api_key" urlEndpoint="https://ik.imagekit.io/your_imagekit_id" src="<full_image_url_from_db>" v-bind:transformation="[{height:300,width:400},{rotation:90}]" |
| 145 | +<IKImage |
| 146 | + publicKey="your_public_api_key" |
| 147 | + urlEndpoint="https://ik.imagekit.io/your_imagekit_id" |
| 148 | + src="<full_image_url_from_db>" |
| 149 | + v-bind:transformation="[{height:300,width:400},{rotation:90}]" /> |
124 | 150 | ```
|
125 | 151 | In the above case, rotation will be performed first and resizing according to width and aspect ratio will be performed afterwards.
|
126 | 152 |
|
127 |
| -#### Low Quality Image Placeholders (LQIP) for images |
128 |
| -The SDK supports automatic support for LQIP for your images, if you set lqip to true in the image component. example: |
| 153 | +#### Low-Quality Image Placeholders (LQIP) for images |
| 154 | +The SDK supports automatic support for LQIP for your images if you set lqip to true in the image component. example: |
| 155 | +
|
| 156 | +```js |
| 157 | +<IKImage |
| 158 | + publicKey="your_public_api_key" |
| 159 | + urlEndpoint="https://ik.imagekit.io/your_imagekit_id" |
| 160 | + v-bind:lqip="{active:true,threshold:20}" /> |
| 161 | +``` |
129 | 162 |
|
130 |
| - ```js |
131 |
| - <IKImage publicKey="your_public_api_key" urlEndpoint="https://ik.imagekit.io/your_imagekit_id" v-bind:lqip="{active:true,threshold:20}"/> |
132 |
| - ``` |
133 |
| -`active` tells the status for lqip, it can be either, `true` or `false` |
134 |
| -`threshold` decided the quaility of placeholder image. It can be any numeric value, a low number means low quality, and high number means high quality. |
| 163 | +`active` tells the status for lqip. It can be either, `true` or `false`. |
| 164 | +`threshold` decides the quality of the placeholder image. It can be any numeric value, a low number means low quality, and a high number means high quality. |
135 | 165 |
|
136 | 166 | ##### How does the lqip work?
|
137 |
| -The component tries to keep the it simple, it loads a lower quality image using the quality parameter to load a lower quality image, which is then replaced with the actual quality image later. |
| 167 | +The component tries to keep it simple. It loads a lower quality image using the quality parameter to load a lower quality image, which is then replaced with the actual quality image later. |
138 | 168 |
|
139 |
| -#### File Upload |
| 169 | +### IKUpload - File Upload |
140 | 170 | The SDK provides a simple Component to upload files to the ImageKit Media Library. It accepts `fileName` parameter as a prop. The file parameter is provided as an input from the user.
|
141 | 171 |
|
142 |
| -Also make sure that you have specified `authenticationEndpoint` during SDK initialization. The SDK makes an HTTP GET request to this endpoint and expects a JSON response with three fields i.e. `signature`, `token` and `expire`. |
| 172 | +Also, make sure that you have specified `authenticationEndpoint` during SDK initialization. The SDK makes an HTTP GET request to this endpoint and expects a JSON response with three fields i.e. `signature`, `token` and `expire`. |
143 | 173 |
|
144 | 174 | [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.
|
145 | 175 |
|
146 | 176 | An example of this server is provided in the samples folder of the SDK.
|
147 | 177 |
|
148 | 178 | Sample Usage
|
149 | 179 | ```js
|
150 |
| - template: '<IKContext publicKey="your_public_api_key" urlEndpoint="https://ik.imagekit.io/your_imagekit_id" authenticationEndpoint="http://www.yourserver.com/auth"><IKUpload fileName="your_desired_filename"/></IKContext>' |
| 180 | +<IKContext |
| 181 | + publicKey="your_public_api_key" |
| 182 | + urlEndpoint="https://ik.imagekit.io/your_imagekit_id" |
| 183 | + authenticationEndpoint="http://www.yourserver.com/auth"> |
| 184 | + <IKUpload fileName="your_desired_filename"/> |
| 185 | +</IKContext> |
| 186 | +``` |
| 187 | +
|
| 188 | +`IKUpload` component accepts all the parameters supported by the [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/client-side-file-upload#request-structure-multipart-form-data) e.g. `tags`, `useUniqueFileName`, `folder` etc. |
| 189 | +
|
| 190 | +You can also use `onSuccess` and `onError` callbacks to handle success and falure respectively, you can simply pass your custom functions to handle the response from API. |
| 191 | +
|
| 192 | +```js |
| 193 | +template: `<IKContext publicKey="${publicKey}" urlEndpoint="https://ik.imagekit.io/your_imagekit_id" authenticationEndpoint="http://www.yourserver.com/auth"><IKUpload fileName="your_desired_filename" :onError="onError" :onSuccess = "onSuccess" /></IKContext>`, |
| 194 | +
|
| 195 | +methods: { |
| 196 | + onError(err) { |
| 197 | + console.log(err); |
| 198 | + }, onSuccess(res) { |
| 199 | + console.log(res); |
| 200 | + }}, |
151 | 201 | ```
|
152 | 202 |
|
153 |
| -`IKUpload` component accepts all the parameters supported by the [ImageKit Upload API](https://docs.imagekit.io/api-reference/upload-file-api/client-side-file-upload#request-structure-multipart-form-data) as props e.g. `tags`, `useUniqueFileName`, `folder` etc. |
| 203 | +## Demo Application |
| 204 | +The fastest way to get started is by running the demo application. You can run the code locally. The source code is in samples/sample-app. For the instructions in [readme.md](https://github.com/imagekit-developer/imagekit-vuejs/blob/master/samples/sample-app/README.md) file within [samples/sample-app](https://github.com/imagekit-developer/imagekit-vuejs/tree/master/samples/sample-app) folder. |
| 205 | +
|
| 206 | +## Support |
| 207 | +
|
| 208 | +For any feedback or to report any issues or general implementation support please reach out to [[email protected]](mailto:[email protected]) |
| 209 | +
|
| 210 | +## Links |
| 211 | +* [Documentation](https://docs.imagekit.io) |
| 212 | +* [Main website](https://imagekit.io) |
| 213 | +
|
| 214 | +## License |
| 215 | +
|
| 216 | +Released under the MIT license. |
0 commit comments