As the title says, I’m trying to attach a file to an existing task, I’m using Nodejs and request() for doing so, but the response says: 400 Bad Request.
I’m going to show you the code for you to see if i’m doing something wrong.
let contents = imagen.image, //this is an array buffer with the image
imageData64 = imagen.imageData64, //this is a base64 code with the mimetype
returnedB64 = imagen.returnedB64,// this is just the base64 code
blob = Buffer.from(returnedB64, ‘base64’),
formData = new FormData();
I haven’t had to do this yet, either, sorry. In addition to the link Bastien posted, you might want to have a look at this forum post about attachments in case it helps:
Thanks for your quick reply,
The Content-Length header is automatic created by XMLHttpRequest.
I also used “\r\n” and two dash in my code, but it does not work.
Now with all the changes, I still got the 400 error with message :
Thanks, I have just tried your recommend above, and the other errors gone.
But it turns into other error message :
“file: File is not an object”
I am going to create an attachment of image file into task. And i have tried using Base64 encode of image as code above, Blob, and File Object. It all not works. Do you have any ideas about this problem?
I do think you’re getting closer. I’m not sure what the cause of “File is not an object” is, other than to suspect, as I think you do, that the issue is in the formatting of the file data you’re sending.
If it were me, I think I would try sending a plain text attachment first - see if you can get that working, then you’ll know everything else is correct and you just need to figure out exactly what Asana is expecting in terms of an image format.
Thanks for your recommendation.
I’ve tried with files from disk and other language like PHP, Python and Yes, It works.
But my problem happens with Javascript.
Seem like when i created a file object from a base64 encoded data to push to Asana instead of read file from disk, the API does not recognize the data posted is File.
I do not know the API accept which type of file data to push to. Maybe it is the Buffer data, but I really want it from normal Javascript because i am not running it on Node.js environment
I was able to make it work by using the http service from Angular, to send a formData request. You can debug using postman. Ping me if you need the code @anon58198851