/cdn-imagekit

CDN service with express and imagekit.io

Primary LanguageJavaScript

Express + ImageKit.io Node.js SDK

Heroku Known Vulnerabilities

This is a starter CDN with Imagekit.io powered by Express

ImageKit Node.js SDK allows you to use image resizing, optimization, file uploading and other ImageKit APIs from applications written in server-side JavaScript.

Table of contents

Installation

  1. Clone this repo
  2. run npm install
  3. run npm run dev for development
  4. run npm start for production

Initialization

  1. rename nodemon.example.json to nodemon.json
  2. edit with your imagekit.io key
{
  "env": {
    "IMAGEKIT_URL_ENDPOINT": "YOUR_IMAGEKIT_URL_ENDPOINT",
    "IMAGEKIT_PUBLIC_KEY": "YOUR_IMAGEKIT_PUBLIC_KEY",
    "IMAGEKIT_PRIVATE_KEY": "YOUR_IMAGEKIT_PRIVATE_KEY"
  }
}

Client Usage

form action="#" onsubmit="upload()">
	<input type="file" id="file1" />
	<input type="submit" />
</form>
<script type="text/javascript" src="../dist/imagekit.js"></script>

<script>
    /* 
        SDK initilization
        
        authenticationEndpoint should be implemented on your server 
        as shown above 
    */
    var imagekit = new ImageKit({
        publicKey : "your_public_api_key",
        urlEndpoint : "https://ik.imagekit.io/your_imagekit_id",
        authenticationEndpoint : "https://www.yourserver.com/auth"
    });
    
    // Upload function internally uses the ImageKit.io javascript SDK
    function upload(data) {
        var file = document.getElementById("file1");
        imagekit.upload({
            file : file.files[0],
            fileName : "abc.jpg",
            tags : ["tag1"]
        }, function(err, result) {
            console.log(arguments);
            console.log(imagekit.url({
                src: result.url,
                transformation : [{ height: 300, width: 400}]
            }));
        })
    }
</script>