# express-imgbb

> express middleware for imgbb

Latest version **2.0.1** (published 2022-01-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-imgbb
pnpm add express-imgbb
yarn add express-imgbb
bun add express-imgbb
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2022-01-03 |
| First published | 2021-04-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 19.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | JeHwanYoo |
| Maintainers | jehwanyoo2 |
| Keywords | express, imgbb, middleware |

## Links

- npm: https://www.npmjs.com/package/express-imgbb
- Repository: https://github.com/JeHwanYoo/express-imgbb
- Homepage: https://github.com/JeHwanYoo/express-imgbb#readme
- Issues: https://github.com/JeHwanYoo/express-imgbb/issues
- npm.io page: https://npm.io/package/express-imgbb

## Dependencies (7)

- [i](https://npm.io/package/i.md) ^0.3.7
- [npm](https://npm.io/package/npm.md) ^8.3.0
- [express](https://npm.io/package/express.md) ^4.17.2
- [form-data](https://npm.io/package/form-data.md) ^4.0.0
- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.6
- [@types/node](https://npm.io/package/@types/node.md) ^17.0.7
- [@types/express](https://npm.io/package/@types/express.md) ^4.17.13

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 2.0.1 (latest) — 2022-01-03
- 1.0.1 — 2021-04-11
- 1.0.0 — 2021-04-11

## README

# EXPRESS-IMGBB

Express Middleware for imgbb

Supports multiple file uploads.

It uses the official imgbb API [https://api.imgbb.com/](https://api.imgbb.com/)

## Usage

Check the official [API document](https://api.imgbb.com/) for detailed usage.

You can use base64 encoding, or web address.

It may be implementable to upload the binary file directly, but it will not be easy to receive the file from the client and send the object again.

In this case, do not use middleware and call the API directly.

```bash
npm install express-imgbb
```

```javascript
const { imgbb } = require('express-imgbb')
const express = require('express')
const path = require('path')
const app = express()

// dotenv is recommended to store the API Key.
const { config } = require('dotenv')
config()

// Because the image size is large, you need to increase the limit.
app.use(express.urlencoded({ extended: true, limit: '32mb' }))
app.use(express.json({ limit: '32mb' }))

// Get an API key from the official website. (https://api.imgbb.com/)
app.set('IMGBB_API_KEY', process.env.API_KEY)

/**
 * For body parameters, refer to the requested schema below.
 */
app.post('/upload', imgbb, (req, res) => {
  const imgbb = req['imgbb']
  const results = imgbb.results
  // ... doing Something
})
```

## Request & Response Schema

```typescript
export type ImgbbRequest = Array<{
  image: string // base64 or url path
  name?: string
  expiration?: number
}>

type ImgbbResponse = {
  results: Array<{
    data?: {
      id: string
      title: string
      url_viewer: string
      url: string
      display_url: string
      size: string
      time: string
      expiration: string
      image: {
        filename: string
        name: string
        mime: string
        extension: string
        url: string
      }
      thumb: {
        filename: string
        name: string
        mime: string
        extension: string
        url: string
      }
      medium: {
        filename: string
        name: string
        mime: string
        extension: string
        url: string
      }
      delete_url: string
    }
    error?: {
      message: string
      code: number
      context: string
    }
    success: boolean
    status: number
  }>
  errors: string[] // Caution, it's not imgbb errors, it's network errors.
}
```

## Example

If you check 'test' directory, there is an example of uploading using the base64 method.

---
_Source: https://npm.io/package/express-imgbb · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
