To add a file to the Media Library, you need to provide the file source as an instance of TemporaryFileUploadData. This object can be instantiated in two ways:
From an UploadedFile instance (for example from a form upload):
$temporaryFileUploadData = TemporaryFileUploadData::fromDisk(
disk: 's3',
path: 'path/to/file.jpg',
shouldPreserveOriginalFile: true// Default false, can be set to true if you want to keep the original file on the disk
);
3
Upload
Next, you can add the instantiated file to the Media Library using the createFile method on the driver instance:
To upload a file to a specific folder, you can instantiate a FileData object for the folder and pass that as the first argument to the createFile() method.
The way you instantiate the $folder depends on your driver:
The entire Media Library can be managed in a programmatic way using the $driver object. This includes upload files, creating folders, moving files, deleting files, renaming files, etc. The below example shows just several of the available methods: