Sending Files

🚧

Currently Javascript Only

Support for sending files is currently only supported in the CLI and Javascript SDK. Support for other platforms will be coming very shortly.

Build has first class support for file types. There are two main ways to pass files into a Build service. You can either pass a buffer or stream directly, or you can use api.file which allows you to pass a path or a url.

Buffer Example

const api = require('api').config('<<keys:api_key>>');
const fs = require('fs');

// This is a real service! Try calling it
// https://readme.build/service/file-demo
api('file-demo').run('scale', { 
  image: fs.readFileSync('./image.jpg'), 
  width: 1000
}, (err, response) => {
  if (err) return console.log(err);
  fs.writeFileSync('./image-2.JPG', response.file);
});

api.file

api.file can accept either a url to a file, or a path to a local file.

const api = require('api').config('<<keys:api_key>>');
const fs = require('fs');

// This is a real service! Try calling it
// https://readme.build/service/file-demo
api('file-test').run('scale', {
  image: api.file('https://files.readme.io/88d46f2-small-logo.png'), 
  width: 100
}, (err, response) => {
  if (err) return console.log(err);
  fs.writeFileSync('./image-2.JPG', response.file);
});

File Response

When a file is returned from a service, it is converted to a standardized format.

{
    filename: file.png, // filename, if known
    type: 'png', // File type
    file: BUFFER // Javascript buffer of the file
  }