Skip to content

handhead/thumbor-upload

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Thumbor Upload

Thumbor Upload

Read the Docs

Setup

Use NPM:

npm install thumbor-upload

or Yarn:

yarn thumbor-upload

Usage

// IMPORT
const { Upload } = require("thumbor-upload");

// CONFIGURE
const THUMBOR_URL = process.env.THUMBOR_URL || 'http://yourserver.com';
const upload = new Upload(THUMBOR_URL);

Load buffer image

From local image

// ...

// STRATEGY 1: LOAD LOCAL BUFFER
const fs = require('fs');
const buffer = fs.readFileSync(path.resolve(__dirname, 'logo-thumbor.png'));

// ...

From remote image

// ...

// 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();

// ...

Create image

Read the docs

// ...

// POST A IMAGE
const { status, headers } = await upload.create(buffer, 'image/png', 'logo-thumbor.png');
const path = headers.get('location');

Upload image

Read the docs

// ...

// 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 image

Read the docs

// ...

// DELETE A IMAGE
const { status, headers } = await upload.delete('/image/05b2eda857314e559630c6f3334d818d/logo-thumbor.png');