Upload attachment to an task file type

I am using asana SDK to upload an attachment to an asana task.

const Asana = require('asana');
const fs = require("fs");

let client = Asana.ApiClient.instance;
let token = client.authentications['token'];
token.accessToken = '<YOUR_ACCESS_TOKEN>';

let attachmentsApiInstance = new Asana.AttachmentsApi();
let opts = { 
    'resource_subtype': "external", 
    'file': fs.createReadStream("file_example"), 
    'parent': "parent_example", 
    'url': "url_example", 
    'name': "name_example", 
    'connect_to_app': true, 
    'opt_fields': "connected_to_app,created_at,download_url,host,name,parent,parent.created_by,parent.name,parent.resource_subtype,permanent_url,resource_subtype,size,view_url"
};
attachmentsApiInstance.createAttachmentForObject(opts).then((result) => {
    console.log('API called successfully. Returned data: ' + JSON.stringify(result.data, null, 2));
}, (error) => {
    console.error(error.response.body);
});

what if the image is saved in S3 and I have the presigned s3 url. What file format should I convert the downloaded image into so that it can be used?

Hi @zicheng_shan,

You may want to download the image from your S3 using something like axios and then upload it as an attachment to Asana using the code you have. If the image is in a common format such as jpg or png and you save the file with the correct extension, you should not have to convert it before uploading. Hope this helps!