ODK Collect sends media files with name of file

I'm a developer working on Apollo (which has some rudimentary ODK support). I'm trying to add support for images, but instead of the attached file coming with the name of the field defined for it (image), it's coming in with the name of the file.

If anyone here is familiar with Flask, instead of the image coming in request.files['image'], the actual key isn't image but the name of the file. I could look at all attachments, but that is a problem because if I have multiple attachments, I wouldn't know what file to match to what field.

It's likely to be something I'm doing wrong, but I'm not sure how to fix it.

2. What app or server are you using and on what device and operating system? Include version numbers.
ODK Collect 1.27.3 on Android Go 8.1.0

3. What you have you tried to fix the problem?
As I mentioned above, I could simply check all uploaded files except for xml_submission_file - in this case, since I'm only expecting a single image, but it's an issue if I was expecting multiple files, each as a response to a specific question.

4. What steps can we take to reproduce the problem?

5. Anything else we should know or have? If you have a test form or screenshots or logs, attach below.
Here's my form XML:

<?xml version="1.0" encoding="UTF-8"?>
<h:html xmlns:h="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/2002/xforms" xmlns:jr="http://openrosa.org/javarosa" xmlns:odk="http://www.opendatakit.org/xforms" xmlns:orx="http://openrosa.org/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <data id="eb80d63b353540beb7cb0e5495fa4d11" orx:version="20200828085438971904">
               <device_id />
               <subscriber_id />
               <phone_number />
               <location />
               <image />
         <bind nodeset="/data/form_id" readonly="true()" />
         <bind nodeset="/data/version_id" readonly="true()" />
         <bind nodeset="/data/device_id" jr:preload="property" jr:preloadParams="deviceid" />
         <bind nodeset="/data/subscriber_id" jr:preload="property" jr:preloadParams="subscriberid" />
         <bind nodeset="/data/phone_number" jr:preload="property" jr:preloadParams="phonenumber" />
         <bind nodeset="/data/location" type="geopoint" />
         <bind nodeset="/data/image" type="image" />
         <input ref="location">
         <upload mediatype="image/*" ref="image">

Here's the server log, including the print out of request.files:

is it ok to open an issue on GitHub for this? i already have a workaround for this (single image case).

Hi and welcome to ODK! I’ve closed your GitHub issue — please do start with conversations on the forum so more community members see it.

If you’re building a system around ODK, I strongly encourage you to consider running Central backend headless and using the API to communicate with your system.

The file names work as intended for the time being. I think there’s a feature thread about possibly rethinking it but that would not happen immediately. We follow the ODK XForms spec and media filenames are provided as part of the submission XML. To match file names and questions, you must parse the submission XML. That will always be the spec-conforming way to access media attachments.

As for your question on GitHub about multiple media files, please try to reproduce any possible issues you run into against Central as this is the server we do quality assurance with and expect to work. I suspect you have a bug in your code receiving media.

thanks for getting back. i'm happy to parse the XML to link the files with their fields. i guess the confusion is from this line in the OpenRosa documentation:

Name: matches an appropriate element inside of the XForm Element's XML.

however, there isn't a bug in the server code. it's literally printing out the data sent to the server via POST and then exiting. i will, however, attempt to see if i can reproduce the same thing with a local install of Central. thanks, and regards.

1 Like

@LN thanks again. the reason only one attachment was getting uploaded was that i had set the OpenRosa request size header in the code that generates the proper headers, and didn't remember it.

1 Like