3.0.1 • Published 4 days ago

imagekitio-vue v3.0.1

Weekly downloads
218
License
MIT
Repository
github
Last release
4 days ago

ImageKit.io Vue.js SDK

Node CI npm version License: MIT Twitter Follow

ImageKit Vue.js SDK allows you to use real-time image resizing, optimization, and file uploading in client-side.

Breaking changes

Upgrading from 2.x to 3.x version

  1. Overlay syntax update
  • In version 3.0.0, we've removed the old overlay syntax parameters for transformations, such as oi, ot, obg, and more. These parameters are deprecated and will start returning errors when used in URLs. Please migrate to the new layers syntax that supports overlay nesting, provides better positional control, and allows more transformations at the layer level. You can start with examples to learn quickly.
  • You can migrate to the new layers syntax using the raw transformation parameter.

Upgrading from 1.x to 2.x version

2.x version has breaking changes as listed below.

  1. In version 2.0.1, three global components, namely ik-image, ik-upload, and ik-context, are no longer supported. Instead, it is recommended to import these components individually.

    
    import { IKImage, IKContext, IKUpload } from "imagekitio-vue"
    
    export default {
      components: {
        IKImage,
        IKContext,
        IKUpload
      }
    }
  2. We have deprecated the use of the authenticationEndpoint parameter. Instead, the SDK has introduced 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.

    An example implementation for authenticator using Fetch API.

    
     const authenticator = async () => {
        try {
    
            // You can also pass headers and validate the request source in the backend, or you can use headers for any other use case.
            const headers = {
              'CustomHeader': 'CustomValue'
            };
    
            const response = await fetch('server_endpoint', {
                headers
            });
    
            if (!response.ok) {
                const errorText = await response.text();
                throw new Error(`Request failed with status ${response.status}: ${errorText}`);
            }
    
            const data = await response.json();
            const { signature, expire, token } = data;
            return { signature, expire, token };
        } catch (error) {
            throw new Error(`Authentication request failed: ${error.message}`);
        }
    };

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.

IMAGEKIT-VUEJS VERSIONVUEJS VERSION
^2.0.1^3.0.0
1.0.9^2.6.12
1.0.5 and below^2.6.11

Installation

npm install --save imagekitio-vue

or

yarn add imagekitio-vue

Usage

Initialization

Import components in your code:

import { IKImage, IKUpload, IKContext, IKVideo, } from 'imagekitio-vue'

Quick examples

<IKContext urlEndpoint="https://ik.imagekit.io/your_imagekit_id">
  // Render an image using a relative path - https://ik.imagekit.io/your_imagekit_id/default-image.jpg
  <IKImage path="/default-image.jpg" />
  // Overriding urlEndpoint defined in parent IkContext - https://www.custom-domain.com/default-image.jpg
  <IKImage urlEndpoint="https://www.custom-domain.com" path="/default-image.jpg" />
  // Render an image using an absolute URL - https://www1.custom-domain.com/default-image.jpg?tr=w-100
  <IKImage src="https://www1.custom-domain.com/default-image.jpg?tr=w-100" />
  // Height and width manipulation - https://ik.imagekit.io/your_imagekit_id/tr:h-200,w-200/default-image.jpg
  <IKImage path="/default-image.jpg" :transformation={[{
    "height": "200",
    "width": "200"
  }]} />
  // Chained transformation - https://ik.imagekit.io/your_imagekit_id/tr:h-200,w-200:rt-90/default-image.jpg
  <IKImage path="/default-image.jpg" :transformation={[{
    "height": "200",
    "width": "200",
  },
  {
    "rotation": "90"
  }]} />
  // Lazy loading image
  <IKImage
    path="/default-image.jpg"
    :transformation={[{
      "height": "200",
      "width": "200"
    }]}
    loading="lazy"
  />
  /*
     Low-quality image placeholder
     Will first load https://ik.imagekit.io/your_imagekit_id/tr:h-200,w-200:q-20,bl-6/default-image.jpg, while the original image, i.e., https://ik.imagekit.io/your_imagekit_id/tr:h-200,w-200/default-image.jpg is being loaded in the background.
  */
  <IKImage
    path="/default-image.jpg"
    :transformation={[{
      "height": "200",
      "width": "200"
    }]}
    :lqip={{ active: true }}
  />
  // Low quality image placeholder with custom quality and blur values
  <IKImage
    path="/default-image.jpg"
    :transformation={[{
      "height": "200",
      "width": "200"
    }]}
    :lqip={{ active: true, quality: 20, blur: 10 }}
  />
  // Low quality image placeholder and lazy loading original image in the background
  <IKImage
    path="/default-image.jpg"
    :transformation={[{
      "height": "200",
      "width": "200"
    }]}
    loading="lazy"
    :lqip={{ active: true }}
  />
  // Video element with basic transaformation, reduced quality by 50% using q: 50

  <IKVideo
    path={'/default-video.mp4'}
    :transformation={[{ height: 200, width: 200, q: 50 }]}
    :controls={true}
  />
</IKContext>


// Controlling quality and blur value of placeholder image
<IKImage
  urlEndpoint="https://ik.imagekit.io/your_imagekit_id"
  path="/default-image.jpg"
  :lqip="{active:true, quality:30, blur: 5}" // default values are quality=20 and blur=6
  :transformation="[{height:300,width:400},{rotation:90}]"
  loading="lazy"
  height="300"
  width="400"
/>
// This promise resolves with an object containing the necessary security parameters i.e `signature`, `token`, and `expire`.
<IKContext publicKey="your_public_api_key" :authenticator="()=>Promise">
  // Simple file upload and response handling
  <IKUpload
    :onError={onError}
    :onSuccess={onSuccess}
  />
  // Passing different upload API options
  <IKUpload
    fileName="file-name.jpg"
    :tags={["sample-tag1", "sample-tag2"]}
    customCoordinates="10,10,10,10"
    :isPrivateFile={false}
    :useUniqueFileName={true}
    :responseFields={["tags"]}
    folder="/sample-folder"
    :ref={uploadRef}
    :onError={onError} 
    :onSuccess={onSuccess}
    :transformation="{
      pre: 'l-text,i-Imagekit,fs-50,l-end', 
      post: [
          {
              type: 'transformation', 
              value: 'w-100'
          }
      ]
    }"
  />
</IKContext>

Demo application

Components

This SDK provides 4 components:

  • IKContext for defining options like urlEndpoint, publicKey or authenticator to all children elements. This component does not render anything.
  • IKImage for image resizing. This renders a <img> tag.
  • IKVideo for video resizing. This renders a <video> tag.
  • IKUploadfor client-side file uploading. This renders a <input type="file"> tag.

If you want to do anything custom, access the ImageKit core JS SDK using IKCore module. For example:

import { IKCore } from "imagekitio-vue"

// Generate image URL
var imagekit = new ImageKit({
    publicKey: "your_public_api_key",
    urlEndpoint: "https://ik.imagekit.io/your_imagekit_id",
});

//https://ik.imagekit.io/your_imagekit_id/endpoint/tr:h-300,w-400/default-image.jpg
var imageURL = imagekit.url({
    path: "/default-image.jpg",
    urlEndpoint: "https://ik.imagekit.io/your_imagekit_id/endpoint/",
    transformation: [{
        "height": "300",
        "width": "400"
    }]
});

IKContext

In order to use the SDK, you need to provide it with a few configuration parameters. You can use a parent IKContext component to define common options for all children IKImage, IKVideo or IKupload compoents. For example:

<IKContext
  :publicKey="your_public_api_key"
  :urlEndpoint="your_url_endpoint"
  :authenticator={()=>Promise} 
  // This promise  resolves with an object containing the necessary security parameters i.e `signature`, `token`, and `expire`.
>
>
  <IKUpload
    :tags="['tag3','tag4']"
    :responseFields="['tags']"
    :onSuccess="onSuccess"
  />
</IKContext>

urlEndpoint is required to use the SDK. You can get URL-endpoint from your ImageKit dashboard - https://imagekit.io/dashboard#url-endpoints.

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.

transformationPosition is optional. The default value for this parameter is path. Acceptable values are path & query

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

Image resizing

The IKImage component renders an img tag. It is used for rendering and manipulating images in real time. IKImage component accepts the following props:

PropTypeDescription
urlEndpointStringOptional. The base URL to be appended before the path of the image. If not specified, the URL-endpoint specified in the parent IKContext component is used. For example, https://ik.imagekit.io/your_imagekit_id/endpoint/
pathStringConditional. This is the path at which the image exists. For example, /path/to/image.jpg. Either the path or src parameter needs to be specified for URL generation.
srcStringConditional. 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 needs to be specified for URL generation.
transformationArray of objectsOptional. 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. See list of different tranformations. Different steps of a chained transformation can be specified as the array's different objects. 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 is applied in the URL as it is.
transformationPositionStringOptional. The default value is path that places the transformation string as a URL path parameter. It can also be specified as query, which adds the transformation string as the URL's query parameter i.e.tr. If you use src parameter to create the URL, then the transformation string is always added as a query parameter.
queryParametersObjectOptional. 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.
loadingStringOptional. Pass lazy to lazy load images
lqipObjectOptional. You can use this to show a low-quality blurred placeholder while the original image is being loaded e.g. {active:true, quality: 20, blur: 6}. The default value of quality is 20 and blur is 6.

Basic resizing examples

// Image from related file path with no transformations - https://ik.imagekit.io/your_imagekit_id/default-image.jpg
<IKContext urlEndpoint="https://ik.imagekit.io/your_imagekit_id">
  <IKImage
    path="/default-image.jpg"
  />

  // Image resizing - https://ik.imagekit.io/your_imagekit_id/tr:w-h-300,w-400/default-image.jpg
  <IKImage
    path="/default-image.jpg"
    :transformation="[{height:300,width:400}]"
  />

  // Loading imgae from an absolute file path with no transformations - https://www.custom-domain.com/default-image.jpg
  <IKImage
    src="https://www.custom-domain.com/default-image.jpg"
  />

  // Using a new tranformation parameter which is not there in this SDK yet - https://ik.imagekit.io/your_imagekit_id/tr:custom-value/default-image.jpg
  <IKImage
    path="/default-image.jpg"
    :transformation="[{custom: 'value'}]"
  />
</IKContext>

The transformation prop is an array of objects. Each object can have the following properties. When you specify more than one object, each object is added as a chained transformation. For example:

// It means first resize the image to 400x400 and then rotate 90 degree
transformation = [
  {
    height: 400,
    width: 400
  },
  {
    rotation: 90
  }
]

See the complete list of transformations supported in ImageKit here. The SDK gives a name to each transformation parameter e.g. height for h and width for w parameter. It makes your code more readable. If the property does not match any of the following supported options, it is added as it is.

Adding overlays

ImageKit.io enables you to apply overlays to images and videos using the raw parameter with the concept of layers. The raw parameter facilitates incorporating transformations directly in the URL. A layer is a distinct type of transformation that allows you to define an asset to serve as an overlay, along with its positioning and additional transformations.

Text as overlays

You can add any text string over a base video or image using a text layer (l-text).

For example:

<IKImage
    path="/default-image.jpg"
    urlEndpoint="https://ik.imagekit.io/your_imagekit_id/endpoint/"
    :transformation="[{ "width": 400, "height": 300, "raw": "l-text,i-Imagekit,fs-50,l-end" }]"
/>

Sample Result URL

https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400,l-text,i-Imagekit,fs-50,l-end/default-image.jpg

Image as overlays

You can add an image over a base video or image using an image layer (l-image).

For example:

<IKImage
    path="/default-image.jpg"
    urlEndpoint="https://ik.imagekit.io/your_imagekit_id/endpoint/"
    :transformation="[{ "width": 400, "height": 300, "raw": "l-image,i-default-image.jpg,w-100,b-10_CDDC39,l-end" }]"
/>

Sample Result URL

https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400,l-image,i-default-image.jpg,w-100,b-10_CDDC39,l-end/default-image.jpg

Solid color blocks as overlays

You can add solid color blocks over a base video or image using an image layer (l-image).

For example:

<IKVideo
    path="/img/sample-video.mp4"
    urlEndpoint="https://ik.imagekit.io/your_imagekit_id/endpoint/"
    :transformation="[{ "width": 400, "height": 300, "raw": "l-image,i-ik_canvas,bg-FF0000,w-300,h-100,l-end" }]"
/>

Sample Result URL

https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400,l-image,i-ik_canvas,bg-FF0000,w-300,h-100,l-end/img/sample-video.mp4

Arithmetic expressions in transformations

ImageKit allows use of arithmetic expressions in certain dimension and position-related parameters, making media transformations more flexible and dynamic.

For example:

<IKImage
    path="/default-image.jpg"
    urlEndpoint="https://ik.imagekit.io/your_imagekit_id/"
    :transformation="[{
        "height": "ih_div_2",
        "width": "iw_div_4",
        "border": "cw_mul_0.05_yellow"
    }]"
/>

Sample Result URL

https://ik.imagekit.io/your_imagekit_id/default-image.jpg?tr=w-iw_div_4,h-ih_div_2,b-cw_mul_0.05_yellow

List of supported transformations

Supported Transformation NameTranslates to parameter
heighth
widthw
aspectRatioar
qualityq
cropc
cropModecm
xx
yy
focusfo
formatf
radiusr
backgroundbg
borderb
rotationrt
blurbl
namedn
progressivepr
losslesslo
trimt
metadatamd
colorProfilecp
defaultImagedi
dprdpr
effectSharpene-sharpen
effectUSMe-usm
effectContraste-contrast
effectGraye-grayscale
effectShadowe-shadow
effectGradiente-gradient
originalorig
rawThe string provided in raw will be added to the URL as it is.

Chained Transforms

Chained transforms make it easy to specify the order the transform is applied. For example:

// Using chained transformation. First, resize and then rotate the image to 90 degrees.
<IKImage
  path="/default-image.jpg"
  :transformation="[{height:300,width:400}, {rotation:90}]"
/>

Lazy loading images

You can lazy load images using the loading prop. When you use loading="lazy", all images that are immediately viewable without scrolling load normally. Those that are far below the device viewport are only fetched when the user scrolls near them.

The SDK uses a fixed threshold based on the effective connection type to ensure that images are loaded early enough so that they have finished loading once the user scrolls near to them.

On fast connections (e.g 4G), the value of threshold is 1250px and on slower connections (e.g 3G), it is 2500px.

You should always set the height and width of image element to avoid layout shift when lazy-loading images.

Example usage:

// Lazy loading images
<IKImage
  urlEndpoint="https://ik.imagekit.io/your_imagekit_id"
  path="/default-image.jpg"
  :transformation="[{height:300,width:400},{rotation:90}]"
  loading="lazy"
  height="300"
  width="400"
/>

Low-quality image placeholders (LQIP)

To improve user experience, you can use a low-quality blurred variant of the original image as a placeholder while the original image is being loaded in the background. Once the loading of the original image is finished, the placeholder is replaced with the original image.

// Loading a blurred low quality image placeholder while the original image is being loaded
<IKImage
  urlEndpoint="https://ik.imagekit.io/your_imagekit_id"
  path="/default-image.jpg"
  :lqip="{active:true}"
/>

By default, the SDK uses the quality:20 and blur:6. You can change this. For example:

<IKImage
  urlEndpoint="https://ik.imagekit.io/your_imagekit_id"
  path="/default-image.jpg"
  :lqip="{active:true, quality: 40, blur: 5}"
/>

Combining lazy loading with low-quality placeholders

You have the option to lazy-load the original image only when the user scrolls near them. Until then, only a low-quality placeholder is loaded. This saves a lot of network bandwidth if the user never scrolls further down.

// Loading a blurred low quality image placeholder and lazy-loading original when user scrolls near them
<IKImage
  urlEndpoint="https://ik.imagekit.io/your_imagekit_id"
  path="/default-image.jpg"
  :transformation="[{height:300,width:400},{rotation:90}]"
  :lqip="{active:true}"
  loading="lazy"
  height="300"
  width="400"
/>

Overriding urlEndpoint for a particular image

You can use urlEndpoint prop in an individual IKImage to change url for that image. For example:

<IKContext urlEndpoint="https://ik.imagekit.io/your_imagekit_id">
  // Changing urlEndpoint
  // https://www.custom-domain.com/tr:w-400,h-300/default-image.jpg
  <IKImage
    path="/default-image.jpg"
    :transformation="[{height:300,width:400}]"
    urlEndpoint="https://www.custom-domain.com"
  />

  // Without urlEndpoint
  // https://ik.imagekit.io/your_imagekit_id/tr:w-400,h-300/default-image.jpg
  <IKImage
    path="/default-image.jpg"
    :transformation="[{height:300,width:400}]"
  />
</IKContext>

Video resizing

The IKVideo component renders a video tag. It is used for rendering and manipulating videos in real-time. IKVideo component accepts the following props:

PropTypeDescription
urlEndpointStringOptional. The base URL to be appended before the path of the video. If not specified, the URL-endpoint specified in the parent IKContext component is used. For example, https://ik.imagekit.io/your_imagekit_id/endpoint/
pathStringConditional. This is the path at which the video exists. For example, /path/to/video.mp4. Either the path or src parameter needs to be specified for URL generation.
srcStringConditional. This is the complete URL of a video already mapped to ImageKit. For example, https://ik.imagekit.io/your_imagekit_id/endpoint/path/to/video.mp4. Either the path or src parameter needs to be specified for URL generation.
transformationArray of objectsOptional. 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. See list of different tranformations. 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.
transformationPositionStringOptional. The default value is path, which 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 the src parameter to create the URL, then the transformation string is always added as a query parameter.
queryParametersObjectOptional. These are the other query parameters that you want to add to the final URL. These can be any query parameters and are not necessarily related to ImageKit. Especially useful if you want to add some versioning parameters to your URLs.

Basic video resizing examples

<IKContext urlEndpoint="https://ik.imagekit.io/demo/your_imagekit_id">
  // Video from related file path with no transformations - https://ik.imagekit.io/demo/your_imagekit_id/sample-video.mp4
  <IKVideo
    path="/sample-video.mp4"
  />
  // Video resizing - https://ik.imagekit.io/demo/your_imagekit_id/tr:w-h-300,w-400/sample-video.mp4
  <IKVideo
    path="/sample-video.mp4"
    transformation={[{
      height:300,
      width:400
    }]}
  />
  // Loading video from an absolute file path with no transformations - https://www.custom-domain.com/default-video.mp4
  <IKVideo
    src="https://www.custom-domain.com/default-video.mp4"
  />
  // Using a new tranformation parameter which is not there in this SDK yet - https://ik.imagekit.io/demo/your_imagekit_id/tr:custom-value/sample-video.mp4
  <IKVideo
    path="/sample-video.mp4"
    transformation={[{
      custom: 'value'
    }]}
  />
</IKContext>

The transformation prop is an array of objects. Each object can have the following properties.

// It means first resize the video to 400x400 and then rotate 90 degree
transformation = [
  {
    height: 400,
    width: 400,
    rt: 90
  }
]

File Upload

The SDK provides the IKUpload component to upload files to the ImageKit Media Library.

IKUpload component accepts the ImageKit Upload API options as props.

PropTypeDescription
fileNameStringOptional. If not specified, the file system name is picked.
useUniqueFileNameBooleanOptional. Accepts true of false. The default value is true. Specify whether to use a unique filename for this file or not.
tagsArray of stringOptional. Set the tags while uploading the file e.g. "tag1","tag2"
folderStringOptional. The folder path (e.g. /images/folder/) in which the file has to be uploaded. If the folder doesn't exist before, a new folder is created.
isPrivateFileBooleanOptional. Accepts true of false. The default value is false. Specify whether to mark the file as private or not. This is only relevant for image type files
customCoordinatesStringOptional. 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
responseFieldsArray of stringOptional. Values of the fields that you want upload API to return in the response. For example, set the value of this field to ["tags", "customCoordinates", "isPrivateFile"] to get value of tags, customCoordinates, and isPrivateFile in the response.
extensionsArray of objectOptional. Array of object for applying extensions on the image.
webhookUrlStringOptional. Final status of pending extensions will be sent to this URL.
overwriteFileBooleanOptional. 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.
overwriteAITagsBooleanOptional. 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.
overwriteCustomMetadataBooleanOptional. 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.
customMetadataObjectOptional. JSON key-value data to be associated with the asset.
refReferenceOptional. Reference to the core HTMLInputElement.
onUploadStartFunction callbackOptional. Called before the upload is started. The first and only argument is the HTML input's change event
onUploadProgressFunction callbackOptional. Called while an upload is in progress. The first and only argument is the ProgressEvent
validateFileFunction callbackOptional. 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
onSuccessFunction callbackOptional. 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
onErrorFunction callbackOptional. Called if upload results in an error. The first and only argument is the error received from the upload API
urlEndpointStringOptional. If not specified, the URL-endpoint specified in the parent IKContext component is used. For example, https://ik.imagekit.io/your_imagekit_id/endpoint/
publicKeyStringOptional. If not specified, the publicKey specified in the parent IKContext component is used.
authenticator()=>Promise<{signature:string,token:string,expiry:number}>Optional. If not specified, the authenticator specified in the parent IKContext component is used.

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.

Sample file upload:

<template>
  <IKUpload 
    :onUploadStart="onUploadStart" 
    :onUploadProgress="onUploadProgress"
    :tags="['tag1','tag2']"
    :responseFields="['tags']"
    :onError="onError"
    :onSuccess="onSuccess"
    customCoordinates="10,10,100,100"
    :transformation="{
      pre: 'l-text,i-Imagekit,fs-50,l-end', 
      post: [
          {
              type: 'transformation', 
              value: 'w-100'
          }
      ]
    }"
  />
</template>

<script>
import { IKUpload } from "imagekitio-vue"

export default {
  name: "app",
  components: {},
  data() {
    return {};
  },
  methods: {
    onError(err) {
      console.log("Error");
      console.log(err);
    },
    onSuccess(res) {
      console.log("Success");
      console.log(res);
    }
    onUploadProgress(evt) {
      console.log("Inprogress ... ", evt);
    };
    onUploadStart(evt) {
      console.log("Upload started");
    },
  }
};
</script>

Abort upload

ref can be passed to obtain access to the IKUpload component's instance. Calling the triggerAbortUpload method will abort the upload if any is in progress.

Example Usage

<template>
  <IKUpload 
    ref="childComponentRef" 
    :publicKey="publicKey" 
    :urlEndpoint="urlEndpoint"
    :authenticator="authenticator"
    :tags="['tag1','tag2']"
    :responseFields="['tags']"
    :onError="onError"
    :onSuccess="onSuccess"
    customCoordinates="10,10,100,100"
    :transformation="{
      pre: 'l-text,i-Imagekit,fs-50,l-end', 
      post: [
          {
              type: 'transformation', 
              value: 'w-100'
          }
      ]
    }"
  />
  <button @click="abortChildUpload">Abort Child Upload</button>
</template>

<script>
import { IKUpload } from "imagekitio-vue"

export default {
  name: "app",
  components: {},
  data() {
    return {};
  },
  methods: {
    onError(err) {
      console.log("Error");
      console.log(err);
    },
    onSuccess(res) {
      console.log("Success");
      console.log(res);
    }
    abortChildUpload() {
      this.$refs.childComponentRef.triggerAbortUpload();
      console.log("Upload aborted")
    },
  }
};
</script>

IKCore

Accessing the underlying ImageKit javascript SDK is possible using the IKCore import. For example:

import { IKCore } from "imagekitio-vue"
// Generate image URL
var imagekit = new IKCore({
    publicKey: "your_public_api_key",
    urlEndpoint: "https://ik.imagekit.io/your_imagekit_id",
});
//https://ik.imagekit.io/your_imagekit_id/endpoint/tr:h-300,w-400/default-image.jpg
var imageURL = imagekit.url({
    path: "/default-image.jpg",
    urlEndpoint: "https://ik.imagekit.io/your_imagekit_id/endpoint/",
    transformation: [{
        "height": "300",
        "width": "400"
    }]
});

Support

For any feedback or to report any issues or general implementation support, please reach out to support@imagekit.io

Links

License

Released under the MIT license.

3.0.1

4 days ago

3.0.0

3 months ago

2.0.1

5 months ago

2.0.0

5 months ago

1.0.9

3 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

0.1.0

4 years ago