The media utils package provides a set of artifacts to abstract media functionality that may be useful in situations where there is a need to deal with media uploads or with the media library, e.g., artifacts that extend or implement a block-editor. This package is meant to be used by the WordPress core. It may not work as expected outside WordPress usages.
Replacement for @wordpress/media-utils
.
Undocumented declaration.
Undocumented declaration.
Uploads a file to the server without creating an attachment.
Parameters
- $0
SideloadMediaArgs
: Parameters object passed to the function. - $0.file
SideloadMediaArgs[ 'file' ]
: Media File to Save. - $0.attachmentId
SideloadMediaArgs[ 'attachmentId' ]
: Parent attachment ID. - $0.additionalData
SideloadMediaArgs[ 'additionalData' ]
: Additional data to include in the request. - $0.signal
SideloadMediaArgs[ 'signal' ]
: Abort signal. - $0.onFileChange
SideloadMediaArgs[ 'onFileChange' ]
: Function called each time a file or a temporary representation of the file is available. - $0.onError
SideloadMediaArgs[ 'onError' ]
: Function called when an error happens.
Transforms an attachment object from the REST API shape into the shape expected by the block editor and other consumers.
Parameters
- attachment
RestAttachment
: REST API attachment object.
Upload a media file when the file upload button is activated or when adding a file to the editor via drag & drop.
Performs some client-side file processing before eventually uploading the media to WordPress.
Similar to the mediaUpload() function from @wordpress/editor
.
Parameters
- $0
UploadMediaArgs
: Parameters object passed to the function. - $0.allowedTypes
UploadMediaArgs[ 'allowedTypes' ]
: Array with the types of media that can be uploaded, if unset all types are allowed. - $0.additionalData
UploadMediaArgs[ 'additionalData' ]
: Additional data to include in the request. - $0.filesList
UploadMediaArgs[ 'filesList' ]
: List of files. - $0.maxUploadFileSize
UploadMediaArgs[ 'maxUploadFileSize' ]
: Maximum upload size in bytes allowed for the site. - $0.onError
UploadMediaArgs[ 'onError' ]
: Function called when an error happens. - $0.onFileChange
UploadMediaArgs[ 'onFileChange' ]
: Function called each time a file or a temporary representation of the file is available. - $0.wpAllowedMimeTypes
UploadMediaArgs[ 'wpAllowedMimeTypes' ]
: List of allowed mime types and file extensions. - $0.signal
UploadMediaArgs[ 'signal' ]
: Abort signal.
Verifies whether the file is within the file upload size limits for the site.
Parameters
- file
File
: File object. - maxUploadFileSize
number
: Maximum upload size in bytes allowed for the site.
Verifies if the caller (e.g. a block) supports this mime type.
Parameters
- file
File
: File object. - allowedTypes
string[]
: List of allowed mime types.
Verifies if the user is allowed to upload this mime type.
Parameters
- file
File
: File object. - wpAllowedMimeTypes
Record< string, string > | null
: List of allowed mime types and file extensions.