5004

Build a Media Gallery

Basics
Medium
Pro
media
mediaset
tenant-media
base64

Build a Media Gallery

Product photos in Business Central don't belong in BLOB fields — the platform ships two dedicated field types, Media for a single image and MediaSet for an ordered collection, which store the bytes once in tenant-media storage and let any number of records reference the same object. Your job is a small gallery API over both: a thumbnail that round-trips byte-identically, a multi-image gallery with positional access, and a share operation that reuses an existing media object instead of storing the bytes twice.

Requirements

Create a table named "Gallery Item" with exactly these fields:

  • "Code", Code[20], the primary key;
  • Thumbnail, a Media field;
  • Images, a MediaSet field.

Create a codeunit named "Media Gallery Mgt." with these public procedures:

procedure SetThumbnail(var GalleryItem: Record "Gallery Item"; Base64Content: Text; MimeType: Text)
procedure GetThumbnail(GalleryItem: Record "Gallery Item"): Text
procedure AddImage(var GalleryItem: Record "Gallery Item"; Base64Content: Text; MimeType: Text): Guid
procedure GetImage(GalleryItem: Record "Gallery Item"; Index: Integer): Text
procedure RemoveImage(var GalleryItem: Record "Gallery Item"; Index: Integer)
procedure ShareImage(SourceItem: Record "Gallery Item"; Index: Integer; var TargetItem: Record "Gallery Item")

Rules:

  1. SetThumbnail decodes Base64Content and stores it in the Thumbnail field, recording MimeType as the content type of the stored media object. Setting a thumbnail on a record that already has one replaces it.
  2. GetThumbnail returns the stored thumbnail as Base64, byte-identical to what was imported — the tests compare the Base64 strings exactly. If the record has no thumbnail, the call must fail with an error whose text contains has no thumbnail.
The rest of the statement and 3 hints Unlock with Pro
ALBusiness Central 28.5
Pro
Pro problem

Solve it with Pro

You’re reading the opening of the statement. Pro unlocks the whole problem:

  • The full statement
  • Starter code in the browser editor
  • 14 grading tests, run on Business Central 28.5
  • 3 hints
  • The reference solution

Pro also opens all 92 Pro problems and lifts the daily limits on compile checks and submissions.

$10 / month
or $100 / year
Upgrade
This problem is part of Pro
Pro unlocks the full statement, tests, hints and solution. The code editor works on a computer.
Upgrade