APIs & services / Firebase

Fallback upload for crop photos that keep failing.

Endpointtoday's app
Call
SDK Firebase Storage userId/farmerId/pliId/pliId.ext
Service
Firebase
Features
Crop Actual (portfolio), Sync error log
When
After N failed photo uploads (ref-data FIREBASE_ATTACHMENT_FALLBACK_UPLOAD_FLAG)
Auth
Firebase app credentials
In the App Service

Use case

Fallback upload for crop (portfolio line item) photos that keep failing on the portfolio-service attachment endpoint. In PortfolioLineItemPicRH.onError, if ref data PORTFOLIO_APP_CONFIG.FIREBASE_ATTACHMENT_UPLOAD_FLAG == 1 and attemptCount >= PORTFOLIO_APP_CONFIG.FIREBASE_ATTACHMENT_UPLOAD_POST_FAIL_COUNT (default 5), FirebaseStorageUtil.uploadImage puts the local file to <userId>/<farmerId>/<pliId>/<pliId>.<ext> (ext defaults to jpg) and blocks with Tasks.await for the download URL. On success the ledger is marked done, PLIImageMeta goes to Firestore pli_image_meta, and the operation is never retried (TryAgain.NEVER). The photo never reaches the platform API; a back-office migration presumably copies it. If the upload returns null, the operation is rewritten to the portfolio custom attachment endpoint and retried later.

Headers

HeaderValueNotes
(Firebase SDK)<Firebase app credentials>No user auth. Access depends on Storage rules (not in the repo).

Parameters

ParamInRequiredExampleNotes
userIdpathYes1001Data.getUserId().
farmerIdpathYes880001Server IE id (resolved from aliasId if needed).
pliIdpathYes7001Server portfolio line item id. Used as both folder and file name.

Request

Example request body (synthetic data)
{
  "part": "image file bytes from PortfolioLineItem.imageUrl (local path)"
}
FieldTypeRequiredNotes
fileimageYesCrop Actual photo. PII: geotagged field or farmer photo.

Response

Example response body (synthetic data)
{
  "downloadUrl": "https://firebasestorage.googleapis.com/v0/b/<bucket>/o/1001%2F880001%2F7001%2F7001.jpg?alt=media&token=<redacted>"
}
FieldTypeRequiredNotes
downloadUrlstringStored as PLIImageMeta.imageUrl in Firestore.

Errors

StatusWhenWhat the app does
SDK exceptionUpload fails or file missinguploadImage returns null and the normal portfolio attachment retry continues.

Source

  • data/src/main/java/org/mindtree/app/agricultor/data/fcm/FirebaseStorageUtil.kt
  • data/src/main/java/org/mindtree/app/agricultor/data/sync/rh/PortfolioLineItemPicRH.kt
  • app/src/main/java/org/platformcommons/urvi/utility/AppUtils.kt
  • data/src/main/java/org/mindtree/app/agricultor/data/Data.kt