편집

다음을 통해 공유


MediaSet.ImportFile(Text, Text [, Text]) Method

Version: Available or changed with runtime version 1.0.

Adds a media, such as a JPEG image, to the MediaSet data type field of a record for displaying the media in the client. The media is imported to the database and included in a MediaSet for the record.

Note

This method is supported only in Business Central on-premises.

Syntax

[ID := ]  MediaSet.ImportFile(Filename: Text, Description: Text [, MimeType: Text])

Parameters

MediaSet
 Type: MediaSet
An instance of the MediaSet data type.

Filename
 Type: Text
Specifies the full path and name of the media file to be imported.

Description
 Type: Text
Specifies text that can be used in the client to describe the media.

[Optional] MimeType
 Type: Text
Specifies 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.

Return Value

[Optional] ID
 Type: Guid
The 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.

Remarks

You use this method to upload a media file as part of a collection of media objects that you want to associate with a record. The method is similar to the ImportFile Method (Media) except that this method enables you to import multiple media files for the same record. For example, you can add multiple images for an item in table 27 Item.

When a media file is imported, a media object is created and stored in the system table 2000000181 Tenant Media of the application database. The media object is assigned a unique identifier (GUID).

In 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.

Example

This example uses the IMPORTFile method to add images to records in table 27 Item of the CRONUS demonstration database.

In support of the example code, you alsmust complete these tasks:

  • Create two sample image files that you want to use on item no. 1000 in table 27 Item.

    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.

  • Verify that table 27 Item has a field that is called Picture and has the data type MediaSet.

    This is field on which you will add the images. If the field is not present, then add it.

With these tasks in place, you can add the following AL code for importing the images. For this code example, create a codeunit, and add the code to the OnRun trigger.

 var
    itemRec: Record Item;
    count: Integer;
    mediasetId: GUID;
    Text000: Label 'The files have been imported. Item %1 has %2 pictures in MediaSet: %3';
begin
    itemRec.Get('1000');
    itemRec.Picture.ImportFile('C:\images\1000-v1.jpg', 'Demo image for item ' + Format(itemRec."No."));
    itemRec.Picture.ImportFile('C:\images\1000-v2.jpg', 'Demo image for item ' + Format(itemRec."No."));
    count := (itemRec.Picture.Count);
    mediasetId := itemRec.Picture.MediaId;  
    Message(Text000,itemRec."No.", count, mediasetId);   
end;

If you run system table 2000000181 Tenant Media, you should see the new images in the list.

MediaSet Data Type
Get Started with AL
Developing Extensions