Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload binary image cf multipart #25

wants to merge 14 commits into
base: master


Copy link

commented Oct 24, 2018

This pull request is an addition to PR #24 allowing to upload an image or binary file as ObjectCustomFieldValues when creating or updating an Objectwith a multipart/form-data POST or PUT request. Here's the doc:

Encoding the content of image or binary files in MIME Base64 has the
drawback of adding some processing overhead and to increase the sent
data size by around 33%. RT's REST2 API provides another way to upload
image or binary files as custom field alues by sending, instead of a
JSON request, a multipart/form-data request. This kind of request is
similar to what the browser sends when you upload a file in RT's ticket
creation or update forms. As its name suggests, a multipart/form-data
request message contains a series of parts, each representing a form
field. To create or update a ticket with image or binary file, the
multipart/form-data request has to include a field named Json, which, as
previously, is a JSON object with Queue, Subject, Content, ContentType,
etc. properties. But instead of specifying each custom field value as a
JSON object with FileName, FileType and FileContent properties, each
custom field value should be a JSON string starting with keyword field:
followed by a field name. You can choose anything you want for this
field name, except Attachement or <attachment_1>, <attachment_2>, etc.
which should be reserved for attching binary files to a response or a
comment to a ticket. Files can then be attached by specifying a field
named as specified in the CustomFields property for each of them, with
the content of the file as value and the appropriate MIME type.

Here is an exemple of a curl invocation, wrapped to multiple lines for
readability, to create a ticket with a multipart/request to upload some
image or binary files as custom fields values.

    curl -X POST
         -H "Content-Type: multipart/form-data"
         -F 'Json={
                    "Queue"      : "General",
                    "Subject"    : "hello world",
                    "Content"    : "That <em>damned</em> printer is out of order <b>again</b>!",
                    "ContentType": "text/html",
                    "CustomFields"  : {
                        "XX_SINGLE_IMAGE_OR_BINARY_CF_ID_XX"   => 'field: FILE_1',
                        "XX_MULTI_VALUE_IMAGE_OR_BINARY_CF_ID" => ['field: FILE_2', 'field: FILE_3']
         -F 'FILE_1=@/tmp/image.png;type=image/png'
         -F 'FILE_1=@/tmp/another_image.png;type=image/png'
         -F 'FILE_2=@/etc/cups/cupsd.conf;type=text/plain'
         -H 'Authorization: token XX_TOKEN_XX'
@gibus gibus referenced this pull request Oct 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
1 participant
You can’t perform that action at this time.