-
-
Notifications
You must be signed in to change notification settings - Fork 88
Open
Labels
Description
I all,
I know there is the excellent qfieldcloud-sdk written in Python to make requests to QFieldCloud API.
I would like to propose a way to test it with CURL. I have managed to test many requests, by failed to upload a JPG image
Do you think this curl examples can benefit for other users ?
# Params
QFIELDCLOUD_URL=https://your.qfieldcloud.yop/api/v1/
QLOGIN=some_user
QPASSWORD=your_password
# Authentication : get token
TOKEN=$(curl -X 'POST' \
${QFIELDCLOUD_URL}auth/login/ \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d "{\"username\": \"${QLOGIN}\", \"password\": \"${QPASSWORD}\"}" | jq -r '.token'
) && echo $TOKEN
# Get user info
echo $(curl -X 'GET' ${QFIELDCLOUD_URL}auth/user/ -H "Authorization: Token ${TOKEN}" -H 'accept: application/json')
# Get user projects
echo $(curl -X 'GET' ${QFIELDCLOUD_URL}projects/ -H "Authorization: Token ${TOKEN}" -H 'Content-Type: application/json' -d '{"limit": "2"}')
# Get files from a given project
PROJECT_ID=072c0a9b-4d45-4a65-8fdb-9c871ca90c8b
echo $(curl -X 'GET' ${QFIELDCLOUD_URL}files/${PROJECT_ID}/ -H "Authorization: Token ${TOKEN}" -H 'Content-Type: application/json' -d '{"skip_metadata": "1"}')
# Download a project file locally
REMOTE_FILE_NAME="media/photos/my_layer/observation_20251013155218713.jpg"
LOCAL_FILE_NAME=/tmp/test.jpg
curl -X GET -L ${QFIELDCLOUD_URL}files/${PROJECT_ID}/${REMOTE_FILE_NAME} -H "Authorization: Token ${TOKEN}" --output "$LOCAL_FILE_NAME" && ls -lh $LOCAL_FILE_NAME
# Upload a file to a project
LOCAL_FILE_NAME=/tmp/test.jpg
REMOTE_FILE_NAME="media/photos/my_layer/test.jpg"
curl -X POST -L ${QFIELDCLOUD_URL}files/${PROJECT_ID}/${REMOTE_FILE_NAME} -H "Authorization: Token ${TOKEN}" -H "Accept: application/json" --form file=@"${LOCAL_FILE_NAME}"
# THE LATTER DOES NOT WORK
# Logs reports the following error : The key \"file\" was not found in `request.data`. Sending report to Sentry.
# I tried with --data-binary or --data with no success
# I tried without the -L with no success
# I also tried without the BASH variable with the real file name like file=@/tmp/test.jpg
The upload failed with returned message {"code":"empty_content","message":"Empty content"}