-
Notifications
You must be signed in to change notification settings - Fork 76
Description
When uploading file attachments to Asana tasks that contain non-ASCII characters in filenames (e.g. Japanese, Cyrillic, Greek characters), the filenames become garbled/corrupted when viewed in Asana web interface.
The issue appears to be related to character encoding handling in the multipart form data upload. The same file uploads work correctly when using Postman, suggesting this is specific to node-asana http client implementation.
Original forum discussion:
https://forum.asana.com/t/attachment-names-uploaded-with-asana-api-are-garbled-on-asanaweb/286200
Expected behavior:
Filenames with non-ASCII characters should display correctly in Asana web interface after upload.
Character encoding should be preserved throughout the upload process
Current behavior:
Filenames with non-ASCII characters appear corrupted/garbled after upload
Japanese, Cyrillic, Greek and other non-ASCII characters are not handled properly
Impact:
This affects any applications using the Node.js client to upload files with non-ASCII filenames to Asana tasks, making the filenames unreadable.
Working axios code with proper encoding:
const axios = require('axios');
const fs = require('fs');
const path = require('path');
const mime = require('mime-types');
require('dotenv').config();
const uploadFileToAsana = async (filePath, parentId) => {
const filename = path.basename(filePath);
const mimeType = mime.lookup(filename) || 'application/octet-stream';
// Generate boundary
const boundary = '----WebKitFormBoundary' + Math.random().toString(36).slice(2);
// Create form data manually
const form = [];
// Add file part
form.push(Buffer.from(`--${boundary}\r\n`));
form.push(Buffer.from(`Content-Disposition: form-data; name="file"; filename*=utf-8''${encodeURIComponent(filename)}\r\n`));
form.push(Buffer.from(`Content-Type: ${mimeType}\r\n\r\n`));
form.push(fs.readFileSync(filePath));
form.push(Buffer.from('\r\n'));
// Add parent part
form.push(Buffer.from(`--${boundary}\r\n`));
form.push(Buffer.from('Content-Disposition: form-data; name="parent"\r\n\r\n'));
form.push(Buffer.from(`${parentId}\r\n`));
form.push(Buffer.from(`--${boundary}--\r\n`));
// Calculate content length
const contentLength = form.reduce((acc, curr) => acc + curr.length, 0);
try {
const response = await axios({
method: 'post',
url: 'https://app.asana.com/api/1.0/attachments',
headers: {
'Authorization': `Bearer YOUR_ASANA_TOKEN`,
'Accept': 'application/json',
'Content-Type': `multipart/form-data; boundary=${boundary}`,
'Content-Length': contentLength
},
data: Buffer.concat(form),
maxBodyLength: Infinity,
maxContentLength: Infinity,
maxRedirects: 20
});
return response.data;
} catch (error) {
console.error('Upload failed:', error.response?.data || error.message);
throw error;
}
};
// Example usage
uploadFileToAsana('./файл.pdf', '1208902923833135')
.then(result => console.log('Upload successful:', result))
.catch(error => console.error('Upload failed:', error));
// module.exports = uploadFileToAsana;
Environment:
Package: asana (npm)
Version: 3.0.11
Node.js environment