REST API Create thread doesn't save attachment

Developer Space

Developer Space
Want to extend the Telligent Evolution platform? Collaborate with other developers and product experts here.

REST API Create thread doesn't save attachment

This question has suggested answer(s)

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?

--3C3F786D6C2076657273696F6E2E@@!!302220656E636F64696E673D662D38223F3E0A3C6D616E6966
Content-Disposition: form-data; name="ForumId"

31
--3C3F786D6C2076657273696F6E2E@@!!302220656E636F64696E673D662D38223F3E0A3C6D616E6966
Content-Disposition: form-data; name="Subject"

Nuther attacvhment
--3C3F786D6C2076657273696F6E2E@@!!302220656E636F64696E673D662D38223F3E0A3C6D616E6966
Content-Disposition: form-data; name="MarkAsRead"

true
--3C3F786D6C2076657273696F6E2E@@!!302220656E636F64696E673D662D38223F3E0A3C6D616E6966
Content-Disposition: form-data; name="Body"

Att

--3C3F786D6C2076657273696F6E2E@@!!302220656E636F64696E673D662D38223F3E0A3C6D616E6966
Content-Disposition: form-data; name="ContentType"

text/plain
--3C3F786D6C2076657273696F6E2E@@!!302220656E636F64696E673D662D38223F3E0A3C6D616E6966
Content-Disposition: form-data; name="FileName"

testfile.txt
Content-Disposition: form-data; name="FileData"

This file contains text only

--3C3F786D6C2076657273696F6E2E@@!!302220656E636F64696E673D662D38223F3E0A3C6D616E6966--
All Replies
  • What version of the platform are you using, and can you share the the complete REST trace?

    Thanks!

  • testattachment.txt

    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.

  • As in this example, telligent.com/.../36679.how-to-upload-a-file-filedata.aspx, 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.

  • 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.

  • 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.