1

I'm trying to attach a file to a task in Asana through the REST API and I'm getting a timeout error. I believe that the error comes from Asana side, so I'm kind of stuck...

The request I'm making has the following format

POST https://app.asana.com/api/1.0/tasks/<my task>/attachments HTTP/1.1
User-Agent: OutSystemsPlatform
Content-Type: multipart/form-data; boundary="<my boundary>"
Authorization: Bearer <my bearer>
Host: app.asana.com
Content-Length: 218

--<my boundary>
content-disposition:  multipart/form-data; name=file; filename=<my filename>;
content-type: image/jpeg
<file binary data>
--<my boundary>--

The reply I get is the following

HTTP/1.1 504 Gateway Time-out
Connection: keep-alive
Content-Length: 176
Content-Type: text/html
Date: Tue, 28 Apr 2015 11:36:03 GMT
Server: nginx

<html>
<head><title>504 Gateway Time-out</title></head>
<body bgcolor="white">
<center><h1>504 Gateway Time-out</h1></center>
<hr><center>nginx</center>
</body>
</html>

Seems to me that the request is well formatted, but it does not work.

Anyone can help?

Thanks Pedro Cardoso

Pedro Cardoso
  • 373
  • 3
  • 7
  • I am currently investigating the scenarios in which we generate this 504. I suspect that the request is actually slightly off and we are having trouble parsing it but I am not sure what specifically is wrong. What language are you trying to perform this in? Are you using any libraries to construct the request? – Andrew Noonan Apr 28 '15 at 19:10
  • I'm using OutSystems Platform. If you don't know it, just visit www.outsystems.com. Basically, this generates a .Net app that runs this requests. The request that I have pasted here is what I see in the logs. Why do you say that the request is a little bit off? – Pedro Cardoso Apr 29 '15 at 20:21
  • Can you test to see which line breaks you are using in your request? As you can [read here](http://stackoverflow.com/questions/5757290/http-header-line-break-style). The HTTP spec is to use `\r\n` for line breaks. Our server will generate a 5xx in the case of a multipart/form-data request that is poorly formed with `\n`. – Andrew Noonan Apr 30 '15 at 00:24

1 Answers1

0

Great question! Unfortunately, multipart/form-data uploads are prone to generating 5xx's due to errors being thrown during the parsing of data happening on the server.

We are working to harden this and return 4xx's where possible.

I suspect you are receiving this error due to improper line termination.

Requests made should follow the HTTP/1.1 specification that line terminators are of the form CRLF or \r\n outlined here in order for the server to reliably and properly handle the request.

Andrew Noonan
  • 848
  • 6
  • 13
  • As far as I can see, the request has the correct characters. Here's a [link](http://screencast.com/t/j0oWQuGK) to a screenshot of the trace in Notepad++ with all characters visible. – Pedro Cardoso May 04 '15 at 15:03
  • In your original post you correctly included your unique boundary, `Content-Disposition` & `Content-Type` headers in the post body, however, I do not see those in the screenshot. Please also make sure that there is an empty line just before and just after the actual file data. – Andrew Noonan May 05 '15 at 18:13
  • Thanks for the update. You don't see it because the body of the request is binary... Here's a [screenshot](http://screencast.com/t/kUcoE6aQUJ6e) to the part of the code where I'm doing it... – Pedro Cardoso May 10 '15 at 10:52
  • That's the problem. Do not convert this data to binary. The purpose of the boundary and MIME part headers is to indicate to the server what the encoding of the data is going to be. Binary encoding this prevents the server from reader the headers. Also do not convert the file data after you read it from disc. Simply indicate the content-type, a new line and the raw file data. After you have confirmed this please comment here and I will update the question & answer to accurately reflect the scenario here. – Andrew Noonan May 11 '15 at 17:52