Twist - Upload Attachment
@sergio
code:
data:privatelast updated:2 years ago
today
Build integrations remarkably fast!
You're viewing a public workflow template.
Sign up to customize, add steps, modify code and more.
Join 800,000+ developers using the Pipedream platform
steps.
trigger
HTTP API
Deploy to generate unique URL
This workflow runs on Pipedream's servers and is triggered by HTTP / Webhook requests.
steps.
send_http_request
auth
to use OAuth tokens and API keys in code via theauths object
params
Target download_filename
 
string ·params.target_download_filename
code
Write any Node.jscodeand use anynpm package. You can alsoexport datafor use in later steps via return or this.key = 'value', pass input data to your code viaparams, and maintain state across executions with$checkpoint.
async (event, steps, params) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
}
16
const axios = require('axios')

const config = {
  method: 'GET',
  url: `https://res.cloudinary.com/da5lyi17v/image/upload/v1599671104/${params.target_download_filename}`,
  responseType: 'arraybuffer',
}

const resp = await axios(config)
const fs = require("fs");
const buffer = Buffer.from(resp.data.toString('base64'), "base64");
fs.writeFileSync(`/tmp/${params.target_download_filename}`, buffer);
this.filename = params.target_download_filename;
steps.
twist_upload_attachment
Uploads a file.
auth
(auths.twist)
params
Filename

Name of the attachment file to upload. Must exist in the related workflow's /tmp folder.

 
string ·params.filename
code
async (params, auths) => {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
}
25
//See the API docs: https://api.twistapp.com/v3/#upload-an-attachment
//See a workflow example of this action: https://pipedream.com/@sergio/twist-upload-attachment-p_n1Cnm9/edit

const FormData = require('form-data');
const fs = require("fs");
const uuid = require('uuid-random');

data = new FormData();
const file = fs.createReadStream(`/tmp/${params.filename}`);
data.append('attachment_id', uuid());
data.append('filename', params.filename);
data.append('file', file);


return await require("@pipedreamhq/platform").axios(this, {
  method: 'post',
  url: `https://api.twist.com/api/v3/attachments/upload`,
  headers: {
    Authorization: `Bearer ${auths.twist.oauth_access_token}`,
    "Content-Type": `multipart/form-data; boundary=${data._boundary}`
  },
  data
});