GOAL exposes a stable client contract under /v1/services/media-server. When MEDIA_SERVER_V2_ENABLED=true, server-to-server calls use roma v2 attachment and stream APIs; when the flag is off (or uploads lack resolvable company_id), behavior falls back to v1.
| Header | Required | Description |
|---|---|---|
Authorization |
yes | Bearer <token> |
x-app-stage |
yes | Application stage (dev, stage, prod, …) |
x-app-uid |
yes | Client application UID |
MEDIA_SERVER_V2_ENABLED=true
| Capability | Flag off | Flag on |
|---|---|---|
| Upload (encoded) | roma POST /v1/attachment/encoded |
roma POST /v2/attachment/encoded when company_id / companyId resolves Company.uuid |
| Upload (bulk) | Same encoded pipeline after base64 conversion | Same v2 rules as encoded |
Metadata GET /{code} |
roma GET /v1/attachment/{code} |
roma GET /v2/attachment/{code} |
| Download stream | roma GET /v1/q/{token} |
roma GET /v2/q/{token} |
| Public CDN URLs | {connector}/v1/q/ |
{connector}/v2/q/ via Goal::mediaUrl() |
Optional override for public stream base (trailing slash included in stored config value semantics below):
MEDIA_SERVER_PUBLIC_STREAM_PATH=https://cdn.example.com/v2/q/
When unset, MediaServerService::publicStreamBaseUrl() builds the base from the MEDIA_SERVER external connector host + /v1/q/ or /v2/q/.
MediaServerService loads staged document goal-setup/media-server-{APP_STAGE} (e.g. media-server-dev, media-server-test). Edit on cluster Couch / Fauxton; expected server values:
| Stage | server |
|---|---|
dev |
https://rms-api-dev.dsroma.info |
test |
https://rms-api-alpha.dsroma.info |
alpha |
https://rms-api-alpha.dsroma.info |
Repo helper: goal-backend/scripts/patch-media-server-couch.php (COUCH_USER, COUCH_PASS). Clear Redis connector cache after changes.
/v1/services/media-server/encodedBase64 upload (primary UI flow).
| Field | Required | Notes |
|---|---|---|
application |
yes | Calling app id |
name |
yes | Original filename |
type |
yes | MIME type |
data |
yes | Base64 payload |
folder |
yes* | Legacy folder; mapped to v2 domain / sub_domain when v2 is active |
storage_preset |
no | Preferred: enum key (branding_media, entity_gallery, …) — see GET …/presets |
owner |
no | Defaults to current user |
company_id / companyId |
no | Required to select v2 upload when flag is on |
reference / entity_uuid |
no* | Entity UUID for v2 object layout (see below) |
domain / sub_domain |
no | Override folder / preset mapping |
branch_id / business_unit_id |
no | Metadata on roma attachment row |
* folder is required unless storage_preset is sent.
* reference is required on the GOAL proxy when v2 is active and company_id resolves — roma v2 stores files under {entity_uuid}/{filename} instead of legacy 2-letter shard folders (ag/, bj/). v1 fallback (no company_id or flag off) does not require reference and keeps existing shard paths on roma.
folder{
"application": "goal-web",
"name": "photo.avif",
"type": "image/avif",
"folder": "media",
"data": "<base64>",
"company_id": 42
}
storage_preset (v2){
"application": "goal-web",
"name": "logo.png",
"type": "image/png",
"storage_preset": "branding_media",
"data": "<base64>",
"company_id": 42,
"reference": "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
}
entity_gallery)Gallery uploads should send the gallery uuid as reference (not numeric id). MinIO key (roma v2):
{company_uuid}/attachments/content/galleries/{gallery_uuid}/{random_filename}
{
"application": "goal-web",
"name": "photo.jpg",
"type": "image/jpeg",
"storage_preset": "entity_gallery",
"data": "<base64>",
"company_id": 42,
"reference": "550e8400-e29b-41d4-a716-446655440000"
}
422 if v2 is selected and reference is missing or not a UUID.
| API | Gallery path segment | Shard folders |
|---|---|---|
v1 POST /v1/attachment/encoded |
galleries/{id}/ag/… (unchanged) |
Yes (ag, bj, …) |
v2 POST /v2/attachment/encoded |
galleries/{entity_uuid}/… |
No — entity UUID only |
Standard ActionResult:
{
"success": true,
"message": "...",
"data": {
"code": "Ab1-xY",
"path": "..."
}
}
Persist code on business entities (image_code, attachment_path, etc.). Do not store MinIO keys.
HTTP status codes: 200 success; 401/403 auth; 422 validation; 500 upstream/connector errors.
/v1/services/media-server/save-bulkMultipart file upload (folder forced to bulk unless storage_preset is provided). Accepts the same optional v2 fields as encoded upload (company_id, storage_preset, domain, …).
/v1/services/media-server/presetsLists approved storage presets for client uploads (v2), the full module_preset_map, and the approved_domains matrix mirrored from roma.
data| Field | Description |
|---|---|
presets |
Array of { key, domain, sub_domain, folder, description, sharded } |
module_preset_map |
GOAL feature keys → preset key |
approved_domains |
Domain → allowed sub_domain values |
sharded_sub_domains |
Sub-domains that used shard folders on legacy v2; v2 encoded upload now uses entity UUID paths (v1 still shards) |
key |
domain / sub_domain |
Typical use |
|---|---|---|
default_draft |
scratchpad / draft | Default staging |
bulk_import |
scratchpad / bulk | Importers, save-bulk |
branding_media |
content / media | Logos, entity upload-image, online store |
entity_gallery |
content / galleries | GoalImageGallery / albums |
user_profile |
content / profiles | Avatars, HR |
pic_share |
content / pic-share | Shared photos |
transactional_document |
transactional / documents | Fleet attachments, receipts |
internal_no_sales |
transactional / no-sales | Internal docs |
compliance_sunat |
compliance / sunat | Compliance via RMS |
Resolution order on upload: storage_preset → explicit domain+sub_domain → folder (exact map, then prefix galleries/) → default. When v2 is active, unapproved pairs return 422.
PHP enums: App\Values\Media\MediaStoragePresetEnum, MediaStorageDomainEnum, MediaStorageSubDomainEnum, MediaLegacyFolderEnum.
module_preset_map (GOAL features → preset)Use these keys in frontends or tooling; upload still uses the preset value in storage_preset.
| Module key | Preset |
|---|---|
services.media_server.default |
default_draft |
services.media_server.save_bulk |
bulk_import |
inventory.master.upload_image |
branding_media |
purchase.supplier.upload_image |
branding_media |
base.company.upload_image |
branding_media |
external_sales.online_store.upload_media |
branding_media |
media_collections.gallery |
entity_gallery |
fleet.work_order_attachment |
transactional_document |
importer.core |
bulk_import |
folder → v2 pair (when preset omitted)Configured in goal-backend config/media_server.php (folder_domain_map + prefix galleries/). Common values: draft, bulk, media, galleries, galleries/{id}, document, receipts, profiles, pic-share, no-sales, sunat.
| Class | Role |
|---|---|
Domain\Media\ResolveMediaStoragePlacementAction |
Resolves placement from preset / domain / folder |
Domain\Media\AssertApprovedMediaStoragePairAction |
422 before v2 upload if pair not in approved_domains |
Domain\Media\ListMediaStoragePresetsAction |
Powers GET …/presets |
Domain\Media\UploadContentToMediaServerAction |
v1/v2 upload routing |
/v1/services/media-server/{code}Attachment metadata from roma (v1 or v2 path behind the flag).
/v1/services/media-server/{code}/downloadProxies roma public stream. GOAL appends a random UUID suffix to the token ({code}.{uuid}) as today.
| Parameter | Description |
|---|---|
thumb=1 |
Request JPEG thumbnail token ({code}.{uuid}-thumb on roma) |
ActionResult with streamed/base64 payload from roma (same envelope as before).
Build URLs as:
{Goal::mediaUrl()}{id}.{code}
Thumbnail:
{Goal::mediaUrl()}{id}.{code}-thumb
Examples: BEES item sync (BeesItemResource), promotion mapping, Goal::logoUrl().
Direct roma (bypass GOAL): GET /v2/q/{id}.{code} — no X-Company-Uuid required for read when object is addressable by code.
goal-backend/.agents/skills/goal-media-server/SKILL.mdgoal-integration-docs/docs/sysadmin/roma-media-server-runtime.mdDomain\Media\UploadContentToMediaServerAction, Domain\Media\DownloadContentAction