APIs & services / assessment-service

Upload an assessment (AIA) attachment.

Endpointtoday's app
Call
POST /gateway/assessment-service/api/v1/aiadefaultresponses/attachment/uuid
Service
assessment-service
Features
Certification survey, Activity Tracker
When
Queued sync (no ledger) after certification
Auth
X-SESSIONID stamped when queued (CoreAPI dooWithRetry); X-REQUESTID idempotency key
In the App Service

Use case

Uploads photos taken as answers in the Certification survey or an Activity History submission. For each answer with an image, CertificationViewModel decodes the base64 image to a temp JPG (saveImage), inserts a local AttachmentEntity, and builds AssessmentUtils.getAttachmentOperation(responseUuid, file). That is a multipart POST that depends on the parent AIA POST through AttachmentIntegrator, queued with dooWithRetry and no ledger. ClearSyncQueueWorker later removes queued uploads whose file no longer exists, after copying the operation to Firestore urvi_attachment_issue. On error it retries later.

Headers

HeaderValueNotes
X-SESSIONID<session id>Stamped by CoreAPI when the queued operation runs (CoreAPIDefaultImpl.doOperation). On a 401 the token is invalidated and the call retried. BaseResponseHandler also refreshes the session after a 500 on a gateway URL (first 5 attempts).
X-REQUESTID(removed)CoreAPIDefaultImpl.processOperation removes X-REQUESTID for multipart requests, so file uploads have no idempotency key.
Content-Typemultipart/form-data; boundary=<generated>Built by CoreAPI makeMultiPartHttpRequest because the operation has a File param.

Parameters

ParamInRequiredExampleNotes
aIADefaultResponseUUIDqueryYesresp-0000-4000-8000-000000000001UUID of the answer (aiadefaultResponseList[].uuid) the file belongs to. ClearSyncQueueWorker matches on this name (UUID_TAG).
attachmentformYesimage123.jpgThe multipart part is named "attachment" (from the library bytecode), not "file". PII: photo of the farmer or field.

Request

Example request body (synthetic data)
{
  "attachment": {
    "part": "binary JPEG decoded from the captured base64 image"
  }
}
FieldTypeRequiredNotes
attachmentfile (image/jpeg)YesSaved under AppUtils.getImagesDir as image*.jpg.

Response

Example response body (synthetic data)
{
  "id": 88001,
  "uuid": "resp-0000-4000-8000-000000000001",
  "fileName": "image123.jpg",
  "mimeType": "image/jpeg",
  "tempURL": "https://<signed-host>/<path>",
  "entityId": 120045,
  "entityType": "AIA_DEFAULT_RESPONSE"
}
FieldTypeRequiredNotes
(body)attachment DTOHandled by the library's AttachmentResponseHandler. Fields are not read by app code. Shape is assumed from the library AttachmentEntity.

Errors

StatusWhenWhat the app does
401Session expiredCoreAPI invalidates the session id and retries once. If it still fails, the response handler returns TryAgain.LATER and the operation stays in the queue.
409Duplicate X-REQUESTIDSyncQueueProcessor records the request id and swaps in a fresh X-REQUESTID for the next attempt.
4xx/5xx (other)Server rejects or failsonError returns TryAgain.LATER (library AttachmentResponseHandler). Each failure is logged in the local error_log table (URL, body, headers). Every 10th attempt (up to attempt 5000) the whole operation is copied to Firestore urvi_sync_log. A 500 on a gateway URL in the first 5 attempts forces a session refresh.
n/a (file missing)Temp image deleted before uploadClearSyncQueueWorker copies the operation to Firestore urvi_attachment_issue and deletes it from the queue on success.

Source

  • app/src/main/java/org/platformcommons/urvi/view/certification/CertificationViewModel.kt
  • app/src/main/java/org/platformcommons/urvi/view/activity_tracker/ActivityHistoryFragment.kt
  • app/src/main/java/org/platformcommons/urvi/datasource/service/ClearSyncQueueWorker.kt
  • jar: commons-assessment-lib-1.0.12-SNAPSHOT AssessmentRepositoryImpl.getAttachmentOperation (proxy for commons-assessment-urvi-lib:1.0.13-SNAPSHOT)