Uploading options and images using the API with curl


#1

Hello there,

I have an issue driving the API with curl when uploading images and setting options at the same time. Since multiple images can only be provided with -F, I must also provide options within a seperate -F. I’ve tried many many different ways, but this is as close as I can get because it actually submits a task, implying that it is both valid JSON and acceptable to ODM:

curl -g --request POST -F 'options[]={"name":"dtm","value":"true"}' -F 'options[]={"name":"dem-resolution","value":"2.0"}' -F "name=Task 2" -F "images=@DJI_0002.JPG" -F "images=@DJI_0003.JPG" https://dom/api/projects/8/tasks/?jwt=$Signiture

But here is the response:

{“id”:“6caa1f83-874a-4017-a40a-76ddb8da69ee”,“project”:8,“processing_node”:null,“processing_node_name”:null,“images_count”:2,“can_rerun_from”:[],“uuid”:"",“name”:“Task 2”,“processing_time”:-1,“auto_processing_node”:true,“status”:null,“last_error”:null,“options”:{},“available_assets”:[],“created_at”:“2019-02-07T22:28:33.652244Z”,“pending_action”:null,“public”:false,“resize_to”:-1,“upload_progress”:0.0,“resize_progress”:0.0,“running_progress”:0.0}

Thinking that it may be an issue with the double option, I try just one:

curl -g --request POST -F 'options[]={"name":"dtm","value":"true"}' -F "name=Task 2" -F "images=@DJI_0002.JPG" -F "images=@DJI_0003.JPG" https://dom/api/projects/8/tasks/?jwt=$Signiture

And get this:

{“id”:“1daacdf0-dd80-4575-b77b-241ccca380b5”,“project”:8,“processing_node”:null,“processing_node_name”:null,“images_count”:2,“can_rerun_from”:[],“uuid”:"",“name”:“Task 2”,“processing_time”:-1,“auto_processing_node”:true,“status”:null,“last_error”:null,“options”:{},“available_assets”:[],“created_at”:“2019-02-07T07:39:03.501862Z”,“pending_action”:null,“public”:false,“resize_to”:-1,“upload_progress”:0.0,“resize_progress”:0.0,“running_progress”:0.0}

In both cases, no options are applied. There are no examples in the documentation on how to supply options (or images), and examples on Google related to the use of -d, which is invalid in this context due to the requirement to upload images.

What am I doing wrong? Thanks guys.


#2

Not sure if this will work, but what happens if you move the brakets?

“options=[{“name”:“dtm”,“value”:“true”}]”


#3

Thanks for the help. Sadly that was one of the ways that I’d already tried. ODM reports:

{“options”:[“Value must be valid JSON.”]}


#4

Here’s a quick way that I’ve been using to test different inputs (on Linux). Make sure to run it from a directory with a couple of images, or specify the path (I use a couple DJI images below as examples):

Replace YOU, YOUR-PASS, DOMAIN, and PROJECT_ID

Signature=$(curl -s --header "Content-Type: application/json" --request POST \
--data '{"username":"YOU","password":"YOUR-PASS"}' \
https://DOMAIN/api/token-auth/| sed 's/"token":\|"\|{\|}//g')

curl -g  --request POST \
-F 'options[]="dtm":"true"' \
-F "name=Task 2" \
-F "images=@DJI_0002.JPG" \
-F "images=@DJI_0003.JPG" \
https://DOMAIN//api/projects/PROJECT_ID/tasks/?jwt=$Signature

#5

Is anybody using the WebODM API successfully?


#6

You are not formatting the options parameter correctly.

Compare it to the following:

curl --request POST -F 'options=[{"name": "dtm", "value": "true"}]' -F "name=Task 2" -F "images=@DJI_0002" -F "images=@DJI_0003.JPG" http://localhost:8000/api/projects/PROJECT_ID/tasks/?jwt=token

See the Python example here: https://docs.webodm.org/#how-to-process-images


#7

Could have sworn that I tried that exact format half a dozen times, but when I pasted what you wrote as-is it works fine.

*Scratches head

Thanks a lot for the help.