Clarify attachments handling in the API

Hello!

I’m using the /api/v2/assets/{uid}/data/{id}/ API to retrieve submissions and donwload attachments.

I’ve noticed that the logic to link attachments with their related question is a bit unclear… here’s an example submission record retrived from the API, with just 2 form questions of type image, and the 2 related attachments:

{
  "_id": 166455,
  ...
  "picture": "1634129991832.jpg",
  "idcard": "1634130005204.jpg",
  "_attachments": [
    {
      "download_url": "https://kobo.oneacrefund.org/api/v2/assets/aPLzYdDLMufaRtECGzB7o4/data/166455/attachments/original/?media_file=yann_jouanique%2Fattachments%2Fc20e20f69b6047c1bfe6ae244bf51a6d%2Fd9c5ad6a-2949-4c61-b248-c38ad43d3520%2F1634130005204.jpg",
      "download_large_url": "https://kobo.oneacrefund.org/api/v2/assets/aPLzYdDLMufaRtECGzB7o4/data/166455/attachments/large/?media_file=yann_jouanique%2Fattachments%2Fc20e20f69b6047c1bfe6ae244bf51a6d%2Fd9c5ad6a-2949-4c61-b248-c38ad43d3520%2F1634130005204.jpg",
      "download_medium_url": "https://kobo.oneacrefund.org/api/v2/assets/aPLzYdDLMufaRtECGzB7o4/data/166455/attachments/medium/?media_file=yann_jouanique%2Fattachments%2Fc20e20f69b6047c1bfe6ae244bf51a6d%2Fd9c5ad6a-2949-4c61-b248-c38ad43d3520%2F1634130005204.jpg",
      "download_small_url": "https://kobo.oneacrefund.org/api/v2/assets/aPLzYdDLMufaRtECGzB7o4/data/166455/attachments/small/?media_file=yann_jouanique%2Fattachments%2Fc20e20f69b6047c1bfe6ae244bf51a6d%2Fd9c5ad6a-2949-4c61-b248-c38ad43d3520%2F1634130005204.jpg",
      "mimetype": "image/jpeg",
      "filename": "yann_jouanique/attachments/c20e20f69b6047c1bfe6ae244bf51a6d/d9c5ad6a-2949-4c61-b248-c38ad43d3520/1634130005204.jpg",
      "instance": 166455,
      "xform": 151,
      "id": 57707
    },
    {
      "download_url": "https://kobo.oneacrefund.org/api/v2/assets/aPLzYdDLMufaRtECGzB7o4/data/166455/attachments/original/?media_file=yann_jouanique%2Fattachments%2Fc20e20f69b6047c1bfe6ae244bf51a6d%2Fd9c5ad6a-2949-4c61-b248-c38ad43d3520%2F1634129991832_0OdlaKJ.jpg",
      "download_large_url": "https://kobo.oneacrefund.org/api/v2/assets/aPLzYdDLMufaRtECGzB7o4/data/166455/attachments/large/?media_file=yann_jouanique%2Fattachments%2Fc20e20f69b6047c1bfe6ae244bf51a6d%2Fd9c5ad6a-2949-4c61-b248-c38ad43d3520%2F1634129991832_0OdlaKJ.jpg",
      "download_medium_url": "https://kobo.oneacrefund.org/api/v2/assets/aPLzYdDLMufaRtECGzB7o4/data/166455/attachments/medium/?media_file=yann_jouanique%2Fattachments%2Fc20e20f69b6047c1bfe6ae244bf51a6d%2Fd9c5ad6a-2949-4c61-b248-c38ad43d3520%2F1634129991832_0OdlaKJ.jpg",
      "download_small_url": "https://kobo.oneacrefund.org/api/v2/assets/aPLzYdDLMufaRtECGzB7o4/data/166455/attachments/small/?media_file=yann_jouanique%2Fattachments%2Fc20e20f69b6047c1bfe6ae244bf51a6d%2Fd9c5ad6a-2949-4c61-b248-c38ad43d3520%2F1634129991832_0OdlaKJ.jpg",
      "mimetype": "image/jpeg",
      "filename": "yann_jouanique/attachments/c20e20f69b6047c1bfe6ae244bf51a6d/d9c5ad6a-2949-4c61-b248-c38ad43d3520/1634129991832_0OdlaKJ.jpg",
      "instance": 166455,
      "xform": 151,
      "id": 57706
    }
  ]
}

As you can see, the value for the 2 image questions is a file name, which I expect can be mapped to one of the attachments’ filename.

However, while the filename for the idcard question (1634130005204.jpg) clearly points to the first attachment in the _attachments array, the one for the picture form question (1634129991832.jpg) does not really clearly point to the second attachment, whose filename is in fact 1634129991832_0OdlaKJ.jpg… The prefix is the same, but the attachment has a suffix that makes the mapping difficult, and more importantly, ambiguous: I’ve seen submissions with multiple attachments with the same prefix (and therefore with more attachments than therer are attachment-based questions in the form)… In this case, how to disambiguate and identify which is the right one?

Most submissions are unambiguous, and I’m not certain how the ambiguities pop up - I suspect this happens when the data collector made several picture attempts (?).

Can someone help clarify the logic here?

1 Like

Hey @Kal_Lam wondering if you have any idea who to route this one to?

Hello @nolive wondering if you have any light to shed here. Attachments mapping logic is not explained in the API docs, and does not seem obvious to me based the above example.

Thanks!

Hello @yjouanique,

Please have a look at this open issue: Add field to `logger.Attachment` that matches question response verbatim · Issue #803 · kobotoolbox/kobocat · GitHub .
We want to improve this.

2 Likes

Indeed, looks like this is what I need… Will watch this one… Thanks!

1 Like