Flag of Ukraine

Node SDK Node SDK

We have a fully featured software development kit for Node.js, to make it easy to talk to the Transloadit REST API from your Node apps.

Install

Note: This documentation is for the current version (v3). Looking for v2 docs? Looking for breaking changes from v2 to v3?

Inside your project, type:

yarn add transloadit

or

npm install --save transloadit

Usage

The following code will upload an image and resize it to a thumbnail:

const Transloadit = require('transloadit')

const transloadit = new Transloadit({
  authKey   : 'YOUR_TRANSLOADIT_KEY',
  authSecret: 'YOUR_TRANSLOADIT_SECRET',
});

(async () => {
  try {
    const options = {
      files: {
        file1: '/PATH/TO/FILE.jpg',
      },
      params: {
        steps: { // You can have many Steps. In this case we will just resize any inputs (:original)
          resize: {
            use   : ':original',
            robot : '/image/resize',
            result: true,
            width : 75,
            height: 75,
          },
        },
        // OR if you already created a template, you can use it instead of "steps":
        // template_id: 'YOUR_TEMPLATE_ID',
      },
      waitForCompletion: true,  // Wait for the Assembly (job) to finish executing before returning
    }

    const status = await transloadit.createAssembly(options)

    if (status.results.resize) {
      console.log('✅ Success - Your resized image:', status.results.resize[0].ssl_url)
    } else {
      console.log("❌ The Assembly didn't produce any output. Make sure you used a valid image file")
    }
  } catch (err) {
    console.error('❌ Unable to process Assembly.', err)
    if (err.assemblyId) {
      console.error(`💡 More info: https://transloadit.com/assemblies/${err.assemblyId}`)
    }
  }
})()

You can find details about your executed Assemblies here.

Examples

For more fully working examples take a look at examples/.

For more example use cases and information about the available robots and their parameters, check out the Transloadit website.

Documentation

See GitHub for the full documentation.

Related blog posts

Uppy
20% off any plan for the Uppy community
Use the UPPY20 code when upgrading.
Sign up
tus
20% off any plan for the tus community
Use the TUS20 code when upgrading.
Sign up
Product Hunt
20% off any plan for Product Hunters
Use the PRH20 code when upgrading.
Sign up