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, aMediafield;Images, aMediaSetfield.
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:
SetThumbnaildecodesBase64Contentand stores it in theThumbnailfield, recordingMimeTypeas the content type of the stored media object. Setting a thumbnail on a record that already has one replaces it.GetThumbnailreturns 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 containshas no thumbnail.
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.
Already on Pro? Sign in