Socket
Socket
Sign inDemoInstall

imgbb-uploader

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imgbb-uploader

Lightweight module to upload images through Imgbb API.


Version published
Weekly downloads
5.4K
decreased by-37.12%
Maintainers
1
Weekly downloads
 
Created
Source

imgbb-uploader

Lightweight Nodejs module to upload local pictures files to imgbb API and get display URLs in response.
Primary use is letting imgBB handle the hosting & serving of images.

https://nodei.co/npm/imgbb-uploader.png?downloads=true&downloadRank=true&stars=true code style: prettier Known Vulnerabilities Build Status

Compatibility:

Node >= 8 ( this module uses async/await )
Care: this module uses fs under the hood. It means it WON'T work outside the node environment !
To upload pictures from your frontend please check the File API instead

Install

npm install imgbb-uploader

Use with two string params (legacy, LTS)

const imgbbUploader = require("imgbb-uploader");

imgbbUploader(
  "your-imgbb-api-key-string",
  "absolute/path/to/your/image/image.png",
)
  .then((response) => console.log(response))
  .catch((error) => console.error(error));

.then((response) => console.log(response)) output example :

{
  id: '26Sy9tM',
  title: '5e7599f65f27',
  url_viewer: 'https://ibb.co/26Sy9tM',
  url: 'https://i.ibb.co/z5FrMR2/5e7599f65f27.png',
  display_url: 'https://i.ibb.co/z5FrMR2/5e7599f65f27.png',
  size: 260258,
  time: '1609336605',
  expiration: '0',
  image: {
    filename: '5e7599f65f27.png',
    name: '5e7599f65f27',
    mime: 'image/png',
    extension: 'png',
    url: 'https://i.ibb.co/z5FrMR2/5e7599f65f27.png'
  },
  thumb: {
    filename: '5e7599f65f27.png',
    name: '5e7599f65f27',
    mime: 'image/png',
    extension: 'png',
    url: 'https://i.ibb.co/26Sy9tM/5e7599f65f27.png'
  },
  delete_url: 'https://ibb.co/26Sy9tM/087a7edaaac26e1c940283df07d0b1d7'
}

This async function returns a promise, so this is normal :
console.log(imgbbUploader(myKey, myPath)) // output : Promise { <pending> }
Your data is available in .then((response) => response) as shown above.

Use with options object (more features, yay! )

From version 1.2.0 onward, you can also pass an options object as param.
Use it to customize filename and/or a set duration after which the image will be deleted, cf their docs.

const imgbbUploader = require("imgbb-uploader");

const options = {
  apiKey: process.env.IMGBB_API_KEY, // MANDATORY
  imagePath: "yourImagePath", // MANDATORY
  name: "yourCustomFilename", // OPTIONAL: pass a custom filename to imgBB API
  expiration: 3600 /* OPTIONAL: pass a numeric value in seconds.

  It must be in the 60-15552000 range (feature based on POSIX time).
  Enable this to force your image to be deleted after that time. */,
};

imgbbUploader(options)
  .then((response) => console.log(response))
  .catch((error) => console.error(error));

/* 
  Same data structure as above; if you provided name and/or expiration value, 
  response.expiration and/or response.image.name will change accordingly.
*/

This module is tiny & totally unlicensed: to better fit your need, please fork away !
Basic instructions for tweaking

Learn more

This module doesn't support array uploads. For heavy duty, you'll probably have to work with fs.readdir and async forEach (you may also be interested in path ).

For example, you can create a baseDir.js file wherever it suits you:

// baseDir.js
const path = require('path');
const dirPath = path.join(__dirname);
module.exports = dirPath;

Then you can require this file elsewhere and use something like path.join(myDirpath, "subfolder") to dig into directories programmatically. Once there, you can f.e. fs.readdir and iterate forEach file of that directory.
See fs documentation and Stack Overflow for more inspiration on the matter.

CHANGELOG

Keywords

FAQs

Package last updated on 30 Dec 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc