Giter VIP home page Giter VIP logo

image-storage's Introduction

ImageStorage API

GitHub GitHub stars Twitter

Host your own images and stay in control

Table of contents

Features

  • Selfhostable
  • Simple upload API
  • 100% file based - no database needed
  • Change and resize your uploads just by editing the URL
  • Securized by secret/public key pair
  • Correctly rendered rotation

Development roadmap

  • Upload file
  • Secret / public key pair authentication
  • Duplicate detection

Installation

Docker

docker run \
  --env "SECRET_KEY=<change-it>" \
  --publish 3000:3000/tcp \
  --volume "${PWD}/images:/data/images" \
  --name image-storage \
  qmachard/image-storage

Docker compose

version: "3.7"
services:
  image-storage:
    image: qmachard/image-storage:latest
    container_name: "image-storage"
    environment:
      - SECRET_KEY=<change-it>
    volumes:
      - <your-path>:/data/images

Manually

Requirements

  • NodeJS v16.15+

Quick Start

  1. Clone or download project
$ git clone [email protected]:qmachard/image-storage.git
  1. Create .env
# .env
PORT=3000
IMAGE_STORAGE=/path/to/directory
SECRET_KEY=change-it
  1. Build and start project
$ yarn && yarn build
$ yarn start
  1. Generate secret / public keys pair
$ node ./generateKey.js
  1. You can use your API from port 3000

http://localhost:3000

API

Signature generation

Signature is a Base64 encoded string which contains values : secret, iv and timestamp.

const signature = Base64(`${secret}.${iv}.${timestamp}`);

Signature can be passed as header X-API-SIGNATURE or query params signature.

Upload Image

POST /images{?signature}

+ Headers

X-API-SIGNATURE=<signature>

+ Body

Content-Disposition: form-data; name="image"; filename="IMG_E2355.jpg"

<content>

+ Response 201 (application/json)

{
  "url": "/images/3e61302a-42cc-4499-8587-5ddcea90f08e.jpeg",
  "filename": "3e61302a-42cc-4499-8587-5ddcea90f08e.jpeg",
  "mimetype": "image/jpeg"
}

Get Image

GET /images/{filename.ext}{?w}{?h}{?signature}

+ Headers

X-API-SIGNATURE=<signature>

+ Response 200 (image/jpeg)

<content>

Query Params

parameter description default
w Max with of image in px null
h Max height of image in px null
signature Signature from secretKey null

This is a Quentin Machard project

image-storage's People

Contributors

qmachard avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.