Rest Service and attachment files

Hello,

I have a form in Kobo with two image question type and a rest service to collect the summits in a custom server. I am having trouble identifying the attachment for each answer in the received json.

For example,

{
  "_id": 119004974,
  "formhub/uuid": "a1a38f8a043743679cde85130fba1736",
  "start": "2021-10-13T15:37:58.770-03:00",
  "end": "2021-10-13T15:38:18.571-03:00",
  "Image1": "17sctouwd9371-15_38_12.jpg",
  "Image2": "!·$%&()=¿¡@#~€¬ªºÇ¨[]{};Capt#ura ' ñ ü d   e pántàllâ 2021-09-20 120808-8_56_59-15_38_16.jpg",
  "__version__": "vz2XjYyMjYkkV77TejR4qH",
  "meta/instanceID": "uuid:98ea9a9e-65ea-413b-a59f-76b9d48c1de3",
  "_xform_id_string": "aWxUyCKgjm7FgpCoVyUoxo",
  "_uuid": "98ea9a9e-65ea-413b-a59f-76b9d48c1de3",
  "_attachments": [
    {
      "download_url": "media/original?media_file=leandrobaroni%2Fattachments%2Fa1a38f8a043743679cde85130fba1736%2F98ea9a9e-65ea-413b-a59f-76b9d48c1de3%2F%C2%AA%C2%BA%C3%87Captura__%C3%B1_%C3%BC_d___e_p%C3%A1nt%C3%A0ll%C3%A2_2021-09-20_120808-8_56_59-15_38_16.jpg",
      "download_large_url": "media/large?media_file=leandrobaroni%2Fattachments%2Fa1a38f8a043743679cde85130fba1736%2F98ea9a9e-65ea-413b-a59f-76b9d48c1de3%2F%C2%AA%C2%BA%C3%87Captura__%C3%B1_%C3%BC_d___e_p%C3%A1nt%C3%A0ll%C3%A2_2021-09-20_120808-8_56_59-15_38_16.jpg",
      "download_medium_url": "media/medium?media_file=leandrobaroni%2Fattachments%2Fa1a38f8a043743679cde85130fba1736%2F98ea9a9e-65ea-413b-a59f-76b9d48c1de3%2F%C2%AA%C2%BA%C3%87Captura__%C3%B1_%C3%BC_d___e_p%C3%A1nt%C3%A0ll%C3%A2_2021-09-20_120808-8_56_59-15_38_16.jpg",
      "download_small_url": "media/small?media_file=leandrobaroni%2Fattachments%2Fa1a38f8a043743679cde85130fba1736%2F98ea9a9e-65ea-413b-a59f-76b9d48c1de3%2F%C2%AA%C2%BA%C3%87Captura__%C3%B1_%C3%BC_d___e_p%C3%A1nt%C3%A0ll%C3%A2_2021-09-20_120808-8_56_59-15_38_16.jpg",
      "mimetype": "image/jpeg",
      "filename": "leandrobaroni/attachments/a1a38f8a043743679cde85130fba1736/98ea9a9e-65ea-413b-a59f-76b9d48c1de3/ªºÇCaptura__ñ_ü_d___e_pántàllâ_2021-09-20_120808-8_56_59-15_38_16.jpg",
      "instance": 119004974,
      "xform": 802953,
      "id": 44020305
    },
    {
      "download_url": "media/original?media_file=leandrobaroni%2Fattachments%2Fa1a38f8a043743679cde85130fba1736%2F98ea9a9e-65ea-413b-a59f-76b9d48c1de3%2F17sctouwd9371-15_38_12.jpg",
      "download_large_url": "media/large?media_file=leandrobaroni%2Fattachments%2Fa1a38f8a043743679cde85130fba1736%2F98ea9a9e-65ea-413b-a59f-76b9d48c1de3%2F17sctouwd9371-15_38_12.jpg",
      "download_medium_url": "media/medium?media_file=leandrobaroni%2Fattachments%2Fa1a38f8a043743679cde85130fba1736%2F98ea9a9e-65ea-413b-a59f-76b9d48c1de3%2F17sctouwd9371-15_38_12.jpg",
      "download_small_url": "media/small?media_file=leandrobaroni%2Fattachments%2Fa1a38f8a043743679cde85130fba1736%2F98ea9a9e-65ea-413b-a59f-76b9d48c1de3%2F17sctouwd9371-15_38_12.jpg",
      "mimetype": "image/jpeg",
      "filename": "leandrobaroni/attachments/a1a38f8a043743679cde85130fba1736/98ea9a9e-65ea-413b-a59f-76b9d48c1de3/17sctouwd9371-15_38_12.jpg",
      "instance": 119004974,
      "xform": 802953,
      "id": 44020304
    }
  ],
  "_status": "submitted_via_web",
  "_geolocation": [
    null,
    null
  ],
  "_submission_time": "2021-10-13T18:38:55",
  "_tags": [],
  "_notes": [],
  "_validation_status": {},
  "_submitted_by": null
}

I tried to match the answer with the attachments by comparing the file name:

"image1": "**17sctouwd9371-15_38_12.jpg**"
"filename": "leandrobaroni/attachments/a1a38f8a043743679cde85130fba1736/98ea9a9e-65ea-413b-a59f-76b9d48c1de3/**17sctouwd9371-15_38_12.jpg**"

but if the filename contains special characters it may differ a lot.

"Image2": "**!\u00b7$%&()=\u00bf\u00a1@#~\u20ac\u00ac\u00aa\u00ba\u00c7\u00a8[]{};Capt#ura ' \u00f1 \u00fc d   e p\u00e1nt\u00e0ll\u00e2 2021-09-20 120808-8_56_59-15_38_16.jpg**"
"filename": "leandrobaroni/attachments/a1a38f8a043743679cde85130fba1736/98ea9a9e-65ea-413b-a59f-76b9d48c1de3/**\u00aa\u00ba\u00c7Captura__\u00f1_\u00fc_d___e_p\u00e1nt\u00e0ll\u00e2_2021-09-20_120808-8_56_59-15_38_16.jpg**"

Hi @leandrobaroni, funnily enough I’ve just had to deal with this. You can see how it’s being handled here in a pending PR:

1 Like