@@ -551,6 +551,118 @@ items in the collection.
551551See the `Searches and selection`_ section for the use cases supported
552552by these features.
553553
554+ Getting Message and Files Content
555+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
556+
557+ You can retreive a message with a url like
558+ ``https://.../demo/rest/data/msg/11``. This returns something like::
559+
560+ {
561+ "data": {
562+ "id": "11",
563+ "type": "msg",
564+ "link": "https://.../demo/rest/data/msg/11",
565+ "attributes": {
566+ "author": {
567+ "id": "5",
568+ "link": "https://.../demo/rest/data/user/5"
569+ },
570+ "content": {
571+ "link": "https://.../demo/msg11/"
572+ },
573+ "date": "2017-10-30.00:53:15",
574+ "files": [],
575+ "inreplyto": null,
576+ "messageid": "<1509324807.14.0.296813919751.issue3@localhost>",
577+ "messagetype": {
578+ "id": "1",
579+ "link": "https://.../demo/rest/data/msgtype/1"
580+ },
581+ "recipients": [
582+ {
583+ "id": "1",
584+ "link": "https://.../demo/rest/data/user/1"
585+ },
586+ {
587+ "id": "3",
588+ "link": "https://.../demo/rest/data/user/3"
589+ },
590+ {
591+ "id": "4",
592+ "link": "https://.../demo/rest/data/user/4"
593+ }
594+ ],
595+ "subject": null,
596+ "summary": "of has to who. or of account give because the",
597+ },
598+ "@etag": "\"584f82231079e349031bbb853747df1c\""
599+ }
600+ }
601+
602+ To retreive the content, you can use the content link property:
603+ ``https://.../demo/msg11/``. The trailing / is required. Without the
604+ /, you get a web page that includes metadata about the message. With
605+ the slash you get a text/plain (in most cases) data stream.
606+
607+ Also you can use the url:
608+
609+ and the content property (if the data is utf-8 compatible) now looks
610+ like::
611+
612+ ...
613+ "author": {
614+ "id": "5",
615+ "link": "https://.../demo/rest/data/user/5"
616+ },
617+ "content": "of has to who pleasure. or of account give because the
618+ reprehenderit\neu to quisquam velit, passage,
619+ was or toil BC quis denouncing quia\nexercise,
620+ veritatis et used voluptas I elit, a The...",
621+ "date": "2017-10-30.00:53:15",
622+ ...
623+
624+ Lines are wrapped for display, content value is one really long
625+ line. If the data is not utf-8 compatible, you will get a link.
626+
627+ Retrieving the contents of a file is slightly different. Performing a
628+ get on a file returns::
629+
630+ {
631+ "data": {
632+ "id": "11",
633+ "type": "file",
634+ "link": "https://.../demo/rest/data/file/11",
635+ "attributes": {
636+ "acl": null,
637+ "content": {
638+ "link": "https://.../demo/file11/"
639+ },
640+ "name": "afile",
641+ "status": {
642+ "id": "1",
643+ "link": "https://.../demo/rest/data/filestatus/1"
644+ },
645+ "type": "image/vnd.microsoft.icon"
646+ },
647+ "@etag": "\"74276f75ef71a30a0cce62dc6a8aa1bb\""
648+ }
649+ }
650+
651+ To get the file contents in binary form, you currently have to go
652+ outside of the rest interface. You can use the name and content link
653+ to download the binary data stream. Perform a get on: the link value
654+ with the name appended. So for this example you would get:
655+ ``https://.../demo/file11/afile``. You will receive a response of type
656+ application/octet-stream.
657+
658+ using ``@verbose=3`` the content is displayed as (wrapped for display)::
659+
660+ "content": "file11 is not text, retrieve using binary_content
661+ property. mdsum: bd990c0f8833dd991daf610b81b62316",
662+
663+
664+ You can then use the `binary_content property`_ described below to
665+ retrieve an encoded copy of the data.
554666
555667Other query params
556668^^^^^^^^^^^^^^^^^^
@@ -804,6 +916,49 @@ The long-form (with ``=``) is different from a query-parameter like
804916``/data/status?name=closed`` which would find all stati (statuses)
805917that have ``closed`` as a substring.
806918
919+ Dealing with Messages and Files
920+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
921+
922+ Using the requests library you can upload a file using::
923+
924+ d = dict (name = filename, content = content, type = content_type)
925+ j = self.post ('file', data = d)
926+
927+ Instead of specifying json = dictionary we specify data = dictionary
928+ as shown above. (We believe) this encodes the contents using
929+ application/x-www-form-urlencoded which is not optimal for large files
930+ due to the encoding overhead.
931+
932+ The requests library can use multipart/form-data which is more
933+ efficient for large files. To do this specify both, files= *and* data=
934+ parameters, e.g.::
935+
936+ # A binary string that can't be decoded as unicode
937+ url = 'https://.../demo/rest/data/'
938+ content = open ('random-junk', 'rb').read ()
939+ fname = 'a-bigger-testfile'
940+ d = dict(name = fname, type='application/octet-stream')
941+ c = dict (content = content)
942+ r = session.post (url + 'file', files = c, data = d)
943+
944+ Curl can be used to post a file using multipart/form-data with::
945+
946+ curl -u demo:demo -s -X POST -H "Referer: https://.../demo/" \
947+ -H "X-requested-with: rest" \
948+ -F "name=afile" -F "type=image/vnd.microsoft.icon" \
949+ -F "content=@doc/roundup-favicon.ico" \
950+ https://.../demo/rest/data/file
951+
952+ the file is located at doc/roundup-favicon.ico. These calls will
953+ return something like::
954+
955+ {
956+ "data": {
957+ "id": "12",
958+ "link": "https://.../demo/rest/data/file/12"
959+ }
960+ }
961+
807962
808963Other Supported Methods for Items
809964^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -851,7 +1006,7 @@ this is returned::
8511006 },
8521007 "type": "issue",
8531008 "link":
854- "https://rouilj.dynamic-dns.net /demo/rest/data/issue/23",
1009+ "https://... /demo/rest/data/issue/23",
8551010 "id": "23"
8561011 }
8571012 }
@@ -867,7 +1022,7 @@ Changing both nosy and title::
8671022 --header "Accept: application/json" \
8681023 --header 'If-Match: "8209add59a79713d64f4d1a072aef740"' \
8691024 --data '{ "nosy": [ "4", "5" ], "title": "This is now my new title" }' \
870- "https://rouilj.dynamic-dns.net /demo/rest/data/issue/23"
1025+ "https://... /demo/rest/data/issue/23"
8711026
8721027which returns both title and nosy attributes::
8731028
@@ -882,7 +1037,7 @@ which returns both title and nosy attributes::
8821037 },
8831038 "type": "issue",
8841039 "link":
885- "https://rouilj.dynamic-dns.net /demo/rest/data/issue/23",
1040+ "https://... /demo/rest/data/issue/23",
8861041 "id": "23"
8871042 }
8881043 }
@@ -984,6 +1139,47 @@ For example::
9841139All endpoints support an ``OPTIONS`` method for determining which
9851140methods are allowed on a given endpoint.
9861141
1142+ Message and File Content
1143+ ^^^^^^^^^^^^^^^^^^^^^^^^
1144+
1145+ Messages and files have content properties. If the data is utf-8
1146+ compatible (e.g. an email message) you can retrieve it with
1147+ rest/data/msg/11/content to obtain::
1148+
1149+ {
1150+ "data": {
1151+ "id": "11",
1152+ "type": "<class 'str'>",
1153+ "link": "https://.../demo/rest/data/msg/11/content",
1154+ "data": "of has to who pleasure. or of account give because the reprehenderit\neu to quisquam velit, passage, was or...",
1155+ "@etag": "\"584f82231079e349031bbb853747df1c\""
1156+ }
1157+ }
1158+
1159+ (the content property is wrapped for display, it is one long line.)
1160+
1161+ .. _binary_content property:
1162+
1163+ If the data is not representable in utf-8, you need to use the
1164+ binary_content
1165+ property. E.G. https://.../demo/rest/data/file/11/binary_content
1166+ returns::
1167+
1168+ {
1169+ "data": {
1170+ "id": "11",
1171+ "type": "<class 'bytes'>",
1172+ "link": "https://.../demo/rest/data/file/11/binary_content",
1173+ "data": "b'\\x00\\x00\\x01\\x00\\x01...\xec?\\x00\\x00'",
1174+ "@etag": "\"74276f75ef71a30a0cce62dc6a8aa1bb\""
1175+ }
1176+ }
1177+
1178+ (data field elided for display). You can also receive the file content
1179+ as a data stream rather than encoded. See `Getting Message and Files
1180+ Content`_.
1181+
1182+
9871183Other Supported Methods for fields
9881184^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9891185
@@ -1657,7 +1853,7 @@ a jwt to see if it's still valid using::
16571853
16581854 curl -s -H "Referer: https://.../demo/" \
16591855 -H "X-requested-with: rest" \
1660- https://rouilj.dynamic-dns.net /demo/rest/jwt/validate?jwt=eyJ0eXAiOiJK... ...XxMDb-Q3oCnMpyhxPXMAk
1856+ https://... /demo/rest/jwt/validate?jwt=eyJ0eXAiOiJK...XxMDb-Q3oCnMpyhxPXMAk
16611857
16621858(note no login is required) which returns::
16631859
0 commit comments