Skip to content

Commit a604d64

Browse files
ANKUR DWIVEDIANKUR DWIVEDI
authored andcommitted
updated readme and validateFile and uploadStarted function in IKUpload
1 parent 19a9ab4 commit a604d64

File tree

2 files changed

+41
-72
lines changed

2 files changed

+41
-72
lines changed

README.md

Lines changed: 38 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,9 @@ yarn add imagekitio-vue
8585
## Usage
8686

8787
### Initialization
88-
Register it as a plugin to install all components globally.
89-
88+
Import components in your code:
9089
```js
91-
import ImageKit from "imagekitio-vue"
90+
import ImageKit, { IKImage, IKUpload, IKContext, IKVideo, } from 'imagekitio-vue'
9291
import { createApp } from 'vue';
9392

9493
const app = createApp({});
@@ -98,18 +97,6 @@ app.use(ImageKit, {
9897
publicKey: "your_public_api_key", // optional
9998
// transformationPosition: "path" // optional
10099
})
101-
```
102-
`urlEndpoint` is required to use the SDK. You can get URL-endpoint from your ImageKit dashboard - https://imagekit.io/dashboard#url-endpoints.
103-
104-
`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#developers.
105-
106-
`transformationPosition` is optional. The default value for this parameter is `path`. Acceptable values are `path` & `query`
107-
108-
_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_
109-
110-
Or, import components individually.
111-
```
112-
import { IKImage, IKVideo, IKContext, IKUpload } from "imagekitio-vue"
113100

114101
export default {
115102
components: {
@@ -119,20 +106,18 @@ export default {
119106
IKUpload
120107
}
121108
}
109+
122110
```
111+
`urlEndpoint` is required to use the SDK. You can get URL-endpoint from your ImageKit dashboard - https://imagekit.io/dashboard#url-endpoints.
123112

124-
### Quick examples
125-
```js
126-
import ImageKit from "imagekitio-vue"
127-
import { createApp } from 'vue';
113+
`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#developers.
128114

129-
const app = createApp({});
115+
`transformationPosition` is optional. The default value for this parameter is `path`. Acceptable values are `path` & `query`
130116

131-
app.use(ImageKit, {
132-
urlEndpoint: "your_url_endpoint", // Required. Default URL-endpoint is https://ik.imagekit.io/your_imagekit_id
133-
publicKey: "your_public_api_key", // optional
134-
})
117+
_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_
135118

119+
### Quick examples
120+
```js
136121
// Rendering image using a relative file path
137122
<IKImage
138123
path="/default-image.jpg"
@@ -193,12 +178,12 @@ app.use(ImageKit, {
193178
// Render an image using an absolute URL - https://www1.custom-domain.com/default-image.jpg?tr=w-100
194179
<IKImage src="https://www1.custom-domain.com/default-image.jpg?tr=w-100" />
195180
// Height and width manipulation - https://ik.imagekit.io/your_imagekit_id/tr:h-200,w-200/default-image.jpg
196-
<IKImage path="/default-image.jpg" transformation={[{
181+
<IKImage path="/default-image.jpg" :transformation={[{
197182
"height": "200",
198183
"width": "200"
199184
}]} />
200185
// Chained transformation - https://ik.imagekit.io/your_imagekit_id/tr:h-200,w-200:rt-90/default-image.jpg
201-
<IKImage path="/default-image.jpg" transformation={[{
186+
<IKImage path="/default-image.jpg" :transformation={[{
202187
"height": "200",
203188
"width": "200",
204189
},
@@ -208,7 +193,7 @@ app.use(ImageKit, {
208193
// Lazy loading image
209194
<IKImage
210195
path="/default-image.jpg"
211-
transformation={[{
196+
:transformation={[{
212197
"height": "200",
213198
"width": "200"
214199
}]}
@@ -220,37 +205,37 @@ app.use(ImageKit, {
220205
*/
221206
<IKImage
222207
path="/default-image.jpg"
223-
transformation={[{
208+
:transformation={[{
224209
"height": "200",
225210
"width": "200"
226211
}]}
227-
lqip={{ active: true }}
212+
:lqip={{ active: true }}
228213
/>
229214
// Low quality image placeholder with custom quality and blur values
230215
<IKImage
231216
path="/default-image.jpg"
232-
transformation={[{
217+
:transformation={[{
233218
"height": "200",
234219
"width": "200"
235220
}]}
236-
lqip={{ active: true, quality: 20, blur: 10 }}
221+
:lqip={{ active: true, quality: 20, blur: 10 }}
237222
/>
238223
// Low quality image placeholder and lazy loading original image in the background
239224
<IKImage
240225
path="/default-image.jpg"
241-
transformation={[{
226+
:transformation={[{
242227
"height": "200",
243228
"width": "200"
244229
}]}
245230
loading="lazy"
246-
lqip={{ active: true }}
231+
:lqip={{ active: true }}
247232
/>
248233
// Video element with basic transaformation, reduced quality by 50% using q: 50
249234

250235
<IKVideo
251236
path={'/default-video.mp4'}
252-
transformation={[{ height: 200, width: 200, q: 50 }]}
253-
controls={true}
237+
:transformation={[{ height: 200, width: 200, q: 50 }]}
238+
:controls={true}
254239
/>
255240
</IKContext>
256241

@@ -266,23 +251,24 @@ app.use(ImageKit, {
266251
/>
267252

268253
// This promise resolves with an object containing the necessary security parameters i.e `signature`, `token`, and `expire`.
269-
<IKContext publicKey="your_public_api_key" authenticator="()=>Promise">
254+
<IKContext publicKey="your_public_api_key" :authenticator="()=>Promise">
270255
// Simple file upload and response handling
271256
<IKUpload
272-
onError={onError}
273-
onSuccess={onSuccess}
257+
:onError={onError}
258+
:onSuccess={onSuccess}
274259
/>
275260
// Passing different upload API options
276261
<IKUpload
277262
fileName="file-name.jpg"
278-
tags={["sample-tag1", "sample-tag2"]}
279-
customCoordinates={"10,10,10,10"}
280-
isPrivateFile={false}
281-
useUniqueFileName={true}
282-
responseFields={["tags"]}
283-
folder={"/sample-folder"}
284-
inputRef={uploadRef}
285-
onError={onError} onSuccess={onSuccess}
263+
:tags={["sample-tag1", "sample-tag2"]}
264+
customCoordinates="10,10,10,10"
265+
:isPrivateFile={false}
266+
:useUniqueFileName={true}
267+
:responseFields={["tags"]}
268+
folder="/sample-folder"
269+
:ref={uploadRef}
270+
:onError={onError}
271+
:onSuccess={onSuccess}
286272
/>
287273
</IKContext>
288274

@@ -341,15 +327,7 @@ app.use(ImageKit, {
341327
<IKImage
342328
path="/default-image.jpg"/>
343329

344-
// Defining urlEndpoint in IKContext
345-
<IKContext
346-
urlEndpoint="https://www.custom-domain.com/">
347-
// https://www.custom-domain.com/default-image.jpg
348-
// urlEndpoint is taken from the parent IKContext
349-
<IKImage path="/default-image.jpg"/>
350-
</IKContext >
351330

352-
// Using exported component
353331
<IKContext
354332
:publicKey="your_url_endpoint"
355333
:urlEndpoint="your_public_api_key"
@@ -367,7 +345,7 @@ app.use(ImageKit, {
367345

368346
## Image resizing
369347

370-
`IKImage` components accept the following props:
348+
The `IKImage` component renders an `img` tag. It is used for rendering and manipulating images in real time. `IKImage` component accepts the following props:
371349

372350
| Prop | Type | Description |
373351
| :----------------| :----|:----------------------------- |
@@ -494,6 +472,7 @@ See the complete list of transformations supported in ImageKit [here](https://do
494472
| effectContrast | e-contrast |
495473
| effectGray | e-grayscale |
496474
| original | orig |
475+
| raw | The string provided in raw will be added to the URL as it is. |
497476

498477
</details>
499478

@@ -672,7 +651,10 @@ The SDK provides the `IKUpload` component to upload files to the [ImageKit Media
672651
| 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. |
673652
| customMetadata | Object | Optional. JSON key-value data to be associated with the asset. |
674653
| ref | Reference | Optional. Reference to the core HTMLInputElement.|
675-
| onSuccess | Function callback | Optional. Called if the upload is successful. The first and only argument is the response JSON from the upload API |
654+
| onUploadStart | Function callback | Optional. Called before the upload is started. The first and only argument is the HTML input's change event |
655+
| onUploadProgress | Function callback | Optional. Called while an upload is in progress. The first and only argument is the ProgressEvent |
656+
| 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 |
657+
| 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) |
676658
| onError | Function callback | Optional. Called if upload results in an error. The first and only argument is the error received from the upload API |
677659
| urlEndpoint | String | Optional. If not specified, the URL-endpoint specified at the time of [SDK initialization](#initialization) is used. For example, https://ik.imagekit.io/your_imagekit_id/endpoint/ |
678660
| publicKey | String | Optional. If not specified, the `publicKey` specified at the time of [SDK initialization](#initialization) is used.|

src/components/IKUpload.vue

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div>
3-
<input type="file" @change="upload" @click="onUploadClick" />
3+
<input type="file" @change="upload" />
44
</div>
55
</template>
66

@@ -105,17 +105,8 @@ export default {
105105
return;
106106
}
107107
108-
109-
if (typeof props.validateFile === "function") {
110-
const validationResult = props.validateFile(file.value);
111-
if (validationResult && validationResult.error) {
112-
if (typeof props.onError === "function") {
113-
props.onError({
114-
message: validationResult.message,
115-
});
116-
}
117-
return;
118-
}
108+
if (typeof props.validateFile === "function" && !props.validateFile(file.value)) {
109+
return;
119110
}
120111
121112
if (typeof props.onUploadStart === "function") {
@@ -209,14 +200,10 @@ export default {
209200
}
210201
};
211202
212-
const onUploadClick = () => {
213-
props.onUploadStart && props.onUploadStart();
214-
};
215203
216204
return {
217205
file,
218206
upload,
219-
onUploadClick,
220207
abortUpload
221208
};
222209
},

0 commit comments

Comments
 (0)