{"title":"MediaSet.ImportStream(InStream, Text [, Text]) Method","url":"https://jonas-paprotka.de/docs/dev-itpro/developer/methods-auto/mediaset/mediaset-importstream-method/","by":"JOP-AL","license":"Copyright (c) Microsoft Corporation. CC BY 4.0, https://creativecommons.org/licenses/by/4.0/; code samples MIT. From https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/mediaset/mediaset-importstream-method, MicrosoftDocs/dynamics365smb-devitpro-pb at 828b6ee (2026-11-19). Changed: includes filled in, links to this site, and for agents shortened without dropping a fact.","credit":"Microsoft Corporation, CC BY 4.0","origin":"https://learn.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/mediaset/mediaset-importstream-method","source":{"name":"Business Central developer and IT pro docs","repo":"https://github.com/MicrosoftDocs/dynamics365smb-devitpro-pb","commit":"828b6ee72fcd75755627cd6011f3d20899217ab2","date":"2026-11-19"},"checked":"2026-11-19","description":"Adds a media file, such as a JPEG image, from an InStream object to the MediaSet of record for displaying in the client.","date":"2026-10-01","meta":{"topic":"reference"},"outline":[{"level":1,"title":"MediaSet.ImportStream(InStream, Text [, Text]) Method","slug":"mediasetimportstreaminstream-text-text-method","at":0,"chars":4405},{"level":2,"title":"Syntax","slug":"syntax","at":318,"chars":108},{"level":2,"title":"Parameters","slug":"parameters","at":426,"chars":799},{"level":2,"title":"Return Value","slug":"return-value","at":1225,"chars":239},{"level":2,"title":"Remarks","slug":"remarks","at":1464,"chars":913},{"level":2,"title":"Example","slug":"example","at":2377,"chars":1892},{"level":2,"title":"Related information","slug":"related-information","at":4269,"chars":136}],"text":"# MediaSet.ImportStream(InStream, Text [, Text]) Method\n> Version: _Available or changed with runtime version 1.0._\nAdds a media file, such as a JPEG image, from an InStream object to the MediaSet of record for displaying in the client. The media is imported to the database and included in a MediaSet for the record.\n## Syntax\n```al\n[ID := ]  MediaSet.ImportStream(Stream: InStream, Description: Text [, MimeType: Text])\n```\n## Parameters\nMediaSet\nType: mediaset-data-type\nAn instance of the mediaset-data-type data type.\nStream\nType: ../instream/instream-data-type\nSpecifies the InStream object that contains the media that you want to use on the record.\nDescription\nType: ../text/text-data-type\nSpecifies text that can be used in the client to describe the media files.\n*[Optional] MimeType*\nType: ../text/text-data-type\nSpecifies the media content type. MIME type is used by browsers, and is an Internet standard to describe the contents of a file. The MimeType value must be a two-part string that consists of a type and subtype, such as image/jpeg or image/gif. If this parameter is not specified, the function will deduct the MIME type from the file extension. For example the MIME type for a .jpg file is image/jpeg.\n## Return Value\n*[Optional] ID*\nType: ../guid/guid-data-type\nThe unique ID that is assigned to the MediaSet of the record. If you omit this optional return value and the operation does not execute successfully, a runtime error will occur.\n## Remarks\nYou can use this method to upload media that you want to associate with a record to the database. For example, you can upload media to items in table 27 Item. The method is similar to the ../media/media-importstream-instream-text-text-method except that this method enables you to import multiple media objects on the same record.\nWhen a media is imported, it is assigned a unique identifier \\(GUID\\) and stored in the system table 2000000181 Tenant Media of the application database.\nIn addition, the media object is assigned to a MediaSet which also has a specific GUID. This GUID is included in the MediaSet data type field as a reference to the media objects. The MediaSet and its GUID are created with the first media that is imported, and the information is stored in table 2000000183 Tenant Media Set. All additional media objects for the record are then associated with the same MediaSet GUID.\n## Example\nThis example uses the ImportStream method to add images to records in table 27 Item of the CRONUS demonstration database.\nTo support the example code that follows, you also have to complete these tasks:\n Create two sample image files that you want to use on item no. 1000 in table 27 Item.\n  Save the images as JPEG type, and give them the names 1000-v1.jpg and 1000-v2.jpg. Save the files in the C:\\images folder on the computer that is running Dynamics 365 Business Central service instance.\n Verify that table 27 Item has a field that is called Picture and has the data type MediaSet.\n  This is field on which you will add the images. If the field is not present, then add it.\nWith these tasks in place, you can add and run the following AL code to import the images. For this code example, create a codeunit and add the code to the OnRun trigger.\n```al\n var\n    itemRec: Record Item;\n    count: Integer;\n    fileName: Text;\n    inStreamObject: InStream;\n    importFile: File;\n    mediasetId: GUID;\n    Text000: Label 'The files have been imported. Item %1 has %2 pictures in MediaSet: %3';\nbegin\n    itemRec.Get('1000');\n\n    fileName := 'C:\\images\\1000-v1.jpg';\n    importFile.Open(fileName);\n    importFile.CreateInStream(inStreamObject);\n    itemRec.Picture.ImportStream(inStreamObject, 'Demo image for item ' + Format(itemRec.\"No.\"));\n    itemRec.Modify;\n    importFile.Close;\n\n    fileName := 'C:\\images\\1000-v2.jpg';\n    importFile.Open(fileName);\n    importFile.CreateInStream(inStreamObject);\n    itemRec.Picture.ImportStream(inStreamObject, 'Demo image for item ' + Format(itemRec.\"No.\"));\n    itemRec.Modify;\n    importFile.Close;\n\n    count := (itemRec.Picture.Count);\n    mediasetId := itemRec.Picture.MediaId;\n    Message(Text000,itemRec.\"No.\",count,mediasetId);\nend;\n```\nIf you run system table 2000000181 Tenant Media, you should see the new images in the list.\n## Related information\nmediaset-data-type\nGet Started with AL<../../devenv-get-started>\nDeveloping Extensions<../../devenv-dev-overview>"}