REST API Create thread doesn't save attachment

I'm creating a new Thread with the REST API endpoint  api.ashx/v2/forums/31/threads.xml - the data is being sent as multipart/form-data and everything works except attachments. The body of the POST request is below. There are no errors or warnings reported. What am I doing wrong?

Content-Disposition: form-data; name="ForumId"

Content-Disposition: form-data; name="Subject"

Nuther attacvhment
Content-Disposition: form-data; name="MarkAsRead"

Content-Disposition: form-data; name="Body"


Content-Disposition: form-data; name="ContentType"

Content-Disposition: form-data; name="FileName"

Content-Disposition: form-data; name="FileData"

This file contains text only

  • What version of the platform are you using, and can you share the the complete REST trace?


  • In reply to Michael Monteleone:

    I've attached a log file. This is a hand-crafted test, but the result is the same when I create a thread in my application.

  • In reply to clydeps:

    As in this example,, you should send the file name and content type within the header of the file's content when using a multipart form data content type for your request.

  • In reply to Ben Tiedt:

    The example you linked to is not applicable to attachments to the forum Thread and Reply endpoints. These specify the use of a "FileData" element to hold the binary file data, not the "file" element in the example. The linked-to example does work for other endpoints, and I have been able to use the apparently undocumented multifileupload.ashx endpoint to create a FileUploadContext which then does work in a Thread or Reply endpoint. But sending binary file data in a Thread endpoint (in the FileData element) results in corruption of the file, specifically bytes with high bit set are replaced with other bytes.

    The FileUploadContext argument is mentioned in several REST endpoints (e.g. user avatar as well as Thread and Replies) but there is nothing in the documentation that I can find that specifies where to get one from. I found the multifileupload.ashx endpoint only by sniffing the web UI.

  • In reply to clydeps:

    The example is applicable.  REST interprets file uploads differently depending on how the request is formatted.  All endpoints supporting file uploading support working as in the example.

    FileUploadContext is exposed to widgets, primarily, via the fileUpload and multipleUpload jQuery plugins.  It is an optimization enabling widgets to save attachments more directly.

    While it can be used by external applications, the multiplefileupload.ashx handler is not directly supported.