Adding a file to the medialibrary is easy. Just pick one of the starting methods, optionally add some of the middle methods
and finish with a finishing method. All start and middle methods are chainable.
For example:
$yourModel
    ->addMedia($pathToFile) 
    ->withCustomProperties(['mime-type' => 'image/jpeg']) 
    ->preservingOriginal() 
    ->toMediaCollection(); 
##Starting methods
##addMedia
public function addMedia($file)
##addMediaFromUrl
public function addMediaFromUrl(string $url)
##addMediaFromRequest
public function addMediaFromRequest(string $keyName): FileAdder
##addMultipleMediaFromRequest
public function addMultipleMediaFromRequest(array $keyNames): Collection
Please note the return type of addMultipleMediaFromRequest is a collection of FileAdders. This means you'll have to loop over every FileAdder to use any of the middle methods. For example:
$fileAdders = $this->model
    ->addMultipleMediaFromRequest(['file-one', 'file-two'])
    ->each(function ($fileAdder) {
        $fileAdder->toMediaCollection();
    });
##addAllMediaFromRequest
public function addAllMediaFromRequest(): Collection
Please note the return type of addAllMediaFromRequest is a Collection of FileAdders. This means you'll have to loop over every FileAdder to use any of the middle methods. See the addMultipleMediaFromRequest method above for an example.
##copyMedia
public function copyMedia($file)
##Middle methods
##preserveOriginal
public function preservingOriginal()
##usingName
public function usingName($name)
##setName
This is an alias for usingName
##usingFileName
public function usingFileName($fileName)
##setFileName
This is an alias for usingFileName
##withCustomProperties
public function withCustomProperties(array $customProperties)
##Finishing methods
##toMediaCollection
public function toMediaCollection($collectionName = 'default', $diskName = '')
##toMediaLibraryOnCloudDisk
This function does almost the same as toMediaLibrary. It'll store all media on the disk configured in the cloud key of config/filesystems.php
 
 public function toMediaLibraryOnCloudDisk(string $collectionName = 'default')