Skip to main content

addSoilImage

@nmi-agro/fdm-source


@nmi-agro/fdm-source / fdm-core/src / addSoilImage

Function: addSoilImage()

addSoilImage(fdm, principal_id, b_id_sampling, input, onUpload?): Promise<any>

Defined in: fdm-core/src/soil-image.ts:36

Adds a soil image record linked to a soil sampling event.

The caller must have write access to the field associated with the sampling. An owner role is granted on the new soil_image resource.

When onUpload is provided it is called with the image path after the permission check but before the DB insert. If onUpload throws the DB record is never created. Note: if onUpload succeeds but the subsequent DB insert fails, the uploaded object may become orphaned and should be cleaned up externally.

Parameters

fdm

PgDatabase

The FDM database instance.

principal_id

any

The ID of the principal performing the operation.

b_id_sampling

any

The ID of the soil sampling event.

input

AddSoilImageInput

Image metadata (path, type, caption, sort order).

onUpload?

(path) => Promise<void>

Optional callback invoked with the image path to trigger the actual storage upload (e.g. GCS). Called after auth, before DB write.

Returns

Promise<any>

The ID of the newly created image record.