Thumbor Upload
Use NPM:
npm install thumbor-upload
or Yarn:
yarn thumbor-upload
// IMPORT
const { Upload } = require("thumbor-upload");
// CONFIGURE
const THUMBOR_URL = process.env.THUMBOR_URL || 'http://yourserver.com';
const upload = new Upload(THUMBOR_URL);
// ...
// STRATEGY 1: LOAD LOCAL BUFFER
const fs = require('fs');
const buffer = fs.readFileSync(path.resolve(__dirname, 'logo-thumbor.png'));
// ...
// ...
// STRATEGY 2: LOAD REMOTE BUFFER
const fetch = require('node-fetch');
const response = await fetch('https://thumbor.readthedocs.io/en/latest/_images/logo-thumbor.png');
const buffer = await response.buffer();
// ...
// ...
// POST A IMAGE
const { status, headers } = await upload.create(buffer, 'image/png', 'logo-thumbor.png');
const path = headers.get('location');
// ...
// PUT A IMAGE
const { status, headers } = await upload.upload(buffer, 'image/png', 'logo-thumbor.png', '/image/05b2eda857314e559630c6f3334d818d/logo-thumbor.png');
const path = headers.get('location');
// ...
// DELETE A IMAGE
const { status, headers } = await upload.delete('/image/05b2eda857314e559630c6f3334d818d/logo-thumbor.png');