Uploading Attachment - "does not conform to the specification for multipart/form-data encoding" [RESOLVED]

SPOILER: The error was a wrongly placed semicolon. (But not in the “usual” way)

Like many other users before me, today I faced the issue of having to upload attachments from a language that has no official API support (namely C#). But the for hours the only thing I was able to accomplish was switching between two error messages:

  1. “file: File is not an object”
    or
  2. “The request body does not conform to the specification for multipart/form-data encoding.”

And I can now explain both of these (unlike the forum posts I was able to find), so I will post the explanation/fixes below, to hopefully save someone in the future the hours of pain and agony I had to endure.

  1. In the multipart/form-data system there’s different types of data and files have a specific formatting that differs from other data. You will get this message when trying to add file as a basic data (even though, according to the documentation, “file” is just a string…pretty misleading).

Solution: You have to use the file format for the file and can’t add it as simple data! More on this in 2)

  1. “But, Julian!”, you say, “whenever I use the file format I will get the error that it does not conform to multipart/form-data”. At least that happened to me. However there seems to be an issue with all multipart/form-data implementations I could find, oooor with the way Asana’s system parses these.

After trying multiple other solutions I used the following implementation, which allowed me to manually check and exactly what was send by my request: C# Multipart File Upload · GitHub

The following is how my NOT WORKING request looks with the implementation I linked above:

--boundary
Content-Disposition: form-data; name="file"; filename="test.png";
Content-Type: image/png

{IMAGE CONTENT HERE}
--boundary
Content-Disposition: form-data; name="name"

{NAME HERE}
--boundary--

And the following is how my WORKING request looks now:

--boundary
Content-Disposition: form-data; name="file"; filename="test.png"
Content-Type: image/png

{IMAGE CONTENT HERE}
--boundary
Content-Disposition: form-data; name="name"

{NAME HERE}
--boundary--

Which brings us to the…
Solution: There is a semicolon after the “filename” parameter of the file and this will lead to Asana not being able to parse the request!
I can only tell for sure for the version I used but I assume this also happens in many other multipart/form-data implementations and it seems to work fine with many(most?) other services so this might actually be an Asana issue.

Sorry if this was a bit long or ranty, but I had to get this off my chest after wasting so much time on this.

2 Likes

Whoa, @Julian_Treffler, thanks so much for posting this info!!

Sorry you had to go through all of that, but I’m quite sure this will be very helpful to others going forward.

(I especially liked the “Spoiler” part.)

@AndrewWong maybe you all can take a look at this?

1 Like