Adding custom properties

When adding a file to the medialibrary you can pass an array with custom properties:

$mediaItem = $newsItem
    ->addMedia($pathToFile)
    ->withCustomProperties(['mime-type' => 'image/jpeg'])
    ->toMediaLibrary();

v3.3+ There are some convenience methods to work with custom properties:

$mediaItem->hasCustomProperty('mime-type'); // returns true
$mediaItem->getCustomProperty('mime-type'); // returns 'image/jpeg'

$mediaItem->hasCustomProperty('does not exists'); // returns false
$mediaItem->getCustomProperty('does not exists'); // returns null

v3.5+ You can also specify a default value when retrieving a custom property.

$mediaItem->getCustomProperty('isPublic', false);