# Can't figure out how to upload Attachments using node-asana

**URL:** <https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017>\
**Category:** API & Developers\
**Tags:** attachments\
**Created:** [2 February 2020 11:08 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017 "2020-02-02T11:08:03Z")\
**Posts on this page:** 18\
**Page:** 2

<div class="post-metadata">

**Author:** ![Ross\_Grambo](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/ross_grambo/32/68568_2.png) [@Ross\_Grambo](https://forum.asana.com/u/Ross_Grambo)\
**Post date:** [11 February 2020 20:03 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/21 "2020-02-11T20:03:04Z")

</div>

This works fine for me:

```auto
// Create a client, getting parameters from the environment.
var client = asana.Client.create({
    clientId: process.env['client_id'],
    clientSecret: process.env['client_secret']
});

client.useOauth();

client.authorize().then(function() {
    // The client is authorized! Make a simple request.
    return client.users.me().then(function(me) {
        console.log('Hello ' + me.name);

        var params = {
            method: 'POST',
            url: "https://app.asana.com/api/1.0/tasks/1234567890/attachments",
            formData: {
                file: fs.createReadStream('test.png')
            },
            headers: {
                "Content-Type": "multipart/form-data"
            },
        };
        client.dispatcher.dispatch(params, {});
    });
}).catch(function(err) {
    console.log('An error occurred', err);
});

```

---

<div class="post-metadata">

**Author:** ![anon89411875](https://luna1.co/8d76cd.png) [@anon89411875](https://forum.asana.com/u/anon89411875)\
**Post date:** [11 February 2020 20:49 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/22 "2020-02-11T20:49:40Z")

</div>

Your solution doesn’t work for me…it is asking to open a link in the browser and enter a code in the command line. The link is broken and I can’t figure out what code it wants as input.  
In your code I can’t see how you authenticate a specific user with his oauth-token.

I use following code to send the request that is failing:

```
const {
  taskGid,
  refresh_token,
  clientId,
  clientSecret,
  redirectUri,
} = process.env;

console.log("authenticating client");
const client = asana.Client.create({
   clientId,
   clientSecret,
   redirectUri
});
client.useOauth({ credentials: { refresh_token } });

console.log("loading file from disk");
const file = fs.createReadStream("src/files/test.png");

console.log("starting fileupload");
client.dispatcher
  .dispatch({
    method: "POST",
    url: `https://app.asana.com/api/1.0/tasks/${taskGid}/attachments`,
    formData: { file },
    headers: {
      "Content-Type": "multipart/form-data"
    }
  })
  .then(response => {
    console.log("SUCCESS", response);
  })
  .catch(e => console.log("ERROR", e));

```

but this request works for me:

```
const options = {
  method: "POST",
  url: "https://app.asana.com/api/1.0/tasks/1234567890/attachments",
  formData: { file },
  headers: {
    "Content-Type": "multipart/form-data",
    Authorization:
      "Bearer XXXXXXXXXXXXXXXXXXXXXXXXX",
    "X-Asana-Client-Lib":
    "version=0.17.3&language=NodeJS&language_version=v8.17.0&os=win32"
  }
};

request(options, function(err, res, payload) {
  console.log(payload);
});

```

---

<div class="post-metadata">

**Author:** ![Ross\_Grambo](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/ross_grambo/32/68568_2.png) [@Ross\_Grambo](https://forum.asana.com/u/Ross_Grambo)\
**Post date:** [11 February 2020 21:26 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/23 "2020-02-11T21:26:53Z")

</div>

In our [Authentication Basics docs](https://developers.asana.com/docs/#authentication-basics) we say “Native or command line applications should use the special redirect URL `urn:ietf:wg:oauth:2.0:oob`”, which is what my script is doing. If you want it to work, go to your Developer Console in Asana and add `urn:ietf:wg:oauth:2.0:oob` as a redirect\_url.

It appears you’re loading your refresh\_token from an env\_variable, which is only appropriate if your app runs for a single user. If it’s only ever going to be run for a single user, you should be using a PAT.

If this app is meant to be used for multiple people, then you should load a refresh token for each person on their first authentication.

Are you building a script that a local computer will run, a website, or a server?

---

<div class="post-metadata">

**Author:** ![anon89411875](https://luna1.co/8d76cd.png) [@anon89411875](https://forum.asana.com/u/anon89411875)\
**Post date:** [12 February 2020 05:05 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/24 "2020-02-12T05:05:30Z")

</div>

I only isolated the attachment code to be sure it is not a problem of my application. In the end it should run on a nodeJS server for multiple users.  
Using the client.authorize() method it always ask me for the credentials. Even i I pass them to the useOauth method. So I think your approach is not suited for my production application.

I am glad I finally have a working example with the pure request method that I can use. I just find it very confusing that I can’t make it work using your asana npm package. In the end it was causing more problems then it helped me.  
I hope you and me can find the issue and your team can fix it so other people don’t have to waste hours and hours to find the problem.

---

<div class="post-metadata">

**Author:** ![Bastien\_Siebman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/bastien_siebman/32/172354_2.png) [@Bastien\_Siebman](https://forum.asana.com/u/Bastien_Siebman)\
**Post date:** [24 March 2020 12:54 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/25 "2020-03-24T12:54:42Z")

</div>

Still not able to make it work either, that is getting very annoying ☹

---

<div class="post-metadata">

**Author:** ![anon89411875](https://luna1.co/8d76cd.png) [@anon89411875](https://forum.asana.com/u/anon89411875)\
**Post date:** [24 March 2020 15:15 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/26 "2020-03-24T15:15:31Z")

</div>

I got it working by using the raw “request” method:

```auto
const options = {
	method: 'POST',
	url: `https://app.asana.com/api/1.0/tasks/${taskGid}/attachments`,
	formData: {
		file: fileStream,
	},
	headers: {
		'Content-Type': 'multipart/form-data',
		Authorization: `Bearer ${bearerToken}`,
	},
}

request(options)

```

it does not work with the asana-client and its dispatch method. Using an OAuth-Token the request will fail. If I’m using a personal-access-token, the asana-client will successfully upload my file.

---

<div class="post-metadata">

**Author:** ![Bastien\_Siebman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/bastien_siebman/32/172354_2.png) [@Bastien\_Siebman](https://forum.asana.com/u/Bastien_Siebman)\
**Post date:** [5 April 2020 08:43 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/27 "2020-04-05T08:43:34Z")

</div>

I managed to make it work using the http service from Angular, after looking at a what a formData postman request looks like. It appears that the Asana dispatcher does not know how to handle form data request, cc @Ross_Grambo

---

<div class="post-metadata">

**Author:** ![anon89411875](https://luna1.co/8d76cd.png) [@anon89411875](https://forum.asana.com/u/anon89411875)\
**Post date:** [5 April 2020 11:53 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/28 "2020-04-05T11:53:49Z")

</div>

It does when using an personal-access-token for authentication. The request will only fail using an OAuth authentication.

---

<div class="post-metadata">

**Author:** ![anon65510617](https://luna1.co/8d76cd.png) [@anon65510617](https://forum.asana.com/u/anon65510617)\
**Post date:** [21 September 2020 16:14 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/29 "2020-09-21T16:14:47Z")

</div>

Same problem with attachments. Is there any way to add an attachment with OAuth at all? To be honest, this problem is really confusing. And even official doc for node.js is wrong as it pointing to method **createAttachmentForTask** which simply does not exists.

---

<div class="post-metadata">

**Author:** ![Ross\_Grambo](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/ross_grambo/32/68568_2.png) [@Ross\_Grambo](https://forum.asana.com/u/Ross_Grambo)\
**Post date:** [23 September 2020 18:37 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/30 "2020-09-23T18:37:12Z")

</div>

I’ll take another look at this.

---

<div class="post-metadata">

**Author:** ![Calvin1](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/calvin1/32/62635_2.png) [@Calvin1](https://forum.asana.com/u/Calvin1)\
**Post date:** [2 October 2020 09:23 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/31 "2020-10-02T09:23:04Z")

</div>

I have the same problem. The #createAttachmentForTask method does not exist.

---

<div class="post-metadata">

**Author:** ![Ivan\_Franco](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/ivan_franco/32/63179_2.png) [@Ivan\_Franco](https://forum.asana.com/u/Ivan_Franco)\
**Post date:** [12 October 2020 21:15 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/32 "2020-10-12T21:15:09Z")

</div>

+1 on this thread, having the same issue. Would love to see a working solution within node-asana!

---

<div class="post-metadata">

**Author:** ![JustinAsanaUser](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/justinasanauser/32/76710_2.png) [@JustinAsanaUser](https://forum.asana.com/u/JustinAsanaUser)\
**Post date:** [4 May 2021 23:10 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/33 "2021-05-04T23:10:57Z")

</div>

Any updates on this? Even with a PAT, it doesn’t look like the asana-client supports uploading files to a task. Please advise.

---

<div class="post-metadata">

**Author:** ![Bastien\_Siebman](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/bastien_siebman/32/172354_2.png) [@Bastien\_Siebman](https://forum.asana.com/u/Bastien_Siebman)\
**Post date:** [19 May 2021 06:53 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/34 "2021-05-19T06:53:04Z")

</div>

@JustinAsanaUser did you see I said I managed to do it? [Can't figure out how to upload Attachments using node-asana - #27 by Bastien\_Siebman](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/27)

---

<div class="post-metadata">

**Author:** ![JustinAsanaUser](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/justinasanauser/32/76710_2.png) [@JustinAsanaUser](https://forum.asana.com/u/JustinAsanaUser)\
**Post date:** [19 May 2021 07:08 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/35 "2021-05-19T07:08:14Z")

</div>

> [@Bastien\_Siebman](#):
>
> I managed to make it work using the http service from Angular, after looking at a what a formData postman request looks like. It appears that the Asana dispatcher does not know how to handle form data request, cc @Ross_Grambo

@Bastien_Siebman I was able to get it working via `axios` and the REST api. Still using the `node-asana` client for a few endpoints, just not the file upload.

---

<div class="post-metadata">

**Author:** ![Lincoln\_Daniel](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/lincoln_daniel/32/112412_2.png) [@Lincoln\_Daniel](https://forum.asana.com/u/Lincoln_Daniel)\
**Post date:** [20 November 2022 17:15 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/36 "2022-11-20T17:15:49Z")

</div>

Got this working in NodeJs with the below and `express-fileupload`

```auto
const fs = require('fs')
const asana = require('asana')

const client = asana.Client.create().useAccessToken(process.env.ASANA_API_PERSONAL_ACCESS_TOKEN)

/**
 * Docs: https://developers.asana.com/docs/attachment
 */
const uploadTaskAttachment = async ({ taskId, file }) => {
  const fileStream = fs.createReadStream(file.tempFilePath)
  // Asana uses the submitted file's path as the name
  fileStream.path = file.name

  return client.dispatcher.dispatch({
    method: 'POST',
    url: 'https://app.asana.com/api/1.0/attachments',
    formData: {
      file: fileStream,
      parent: taskId,
    },
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  })
}

```

---

<div class="post-metadata">

**Author:** ![Lincoln\_Daniel](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/lincoln_daniel/32/112412_2.png) [@Lincoln\_Daniel](https://forum.asana.com/u/Lincoln_Daniel)\
**Post date:** [2 January 2023 18:45 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/37 "2023-01-02T18:45:43Z")

</div>

To be clear, the `express-fileupload` package can be found here for those using the Express framework in NodeJS [express-fileupload - npm](https://www.npmjs.com/package/express-fileupload)

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/system/32/276370_2.png) [@system](https://forum.asana.com/u/system)\
**Post date:** [30 May 2025 18:56 UTC](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017/38 "2025-05-30T18:56:00Z")

</div>

Closed on 30 May 2025 18:56 UTC



[Previous page](https://forum.asana.com/t/cant-figure-out-how-to-upload-attachments-using-node-asana/73017.md?page=1)
