Media Library Handler
Plugin for handling media library (dirs/files manipulation) through api in Strapi.
strapi-plugin-media-library-handler
Plugin for handling media library (dirs/files manipulation) through api in Strapi.
Features
- Manage folders and files through API.
- Easy integration with Strapi projects.
Installation
npm i strapi-plugin-media-library-handlerCompatibility
Plugin is compatible with Strapi 5.0.0 and above.
Media & Folder Management API
Configuration
No additional configuration needed, the plugin is automatically enabled after installation.
Generate API Token (with proper permissions for Media section) which would be provided as Authorization header to each API call.
Folders
Create Folder
Create a new folder.
1POST {STRAPI_BASE_URL}/api/media/folders
2Content-Type: application/jsonRequest Body
1{
2 "name": "My New Folder",
3 "parentId": 123
4}Response (201)
1{
2 "id": 456,
3 "name": "My New Folder",
4 "parent": null,
5 "createdAt": "2025-05-05T12:34:56.789Z",
6 ...
7}Errors
400 Bad Request– validation failed.500 Internal Server Error– unexpected error.
List Folders
Retrieve folders, with optional search and sorting.
1GET {STRAPI_BASE_URL}/api/media/folders?parentId=123&_q=term&sort=name:asc&sort=createdAt:descQuery Parameters
parentId(integer) — optional, filter by parent folder (omit or null for root)_q(string) — optional, full-text search stringsort(string) — optional, repeatable. Format:field:asc|desc.
Response (200)
1[
2 {
3 "id": 123,
4 "name": "Root Folder",
5 "children": { "count": 2 },
6 "files": { "count": 5 },
7 ...
8 }
9]Get Folder
Get a specific folder by its ID, including nested parents up to 5 levels.
1GET {STRAPI_BASE_URL}/api/media/folders/:idPath Parameter
id(integer) — required, positive folder ID.
Response (200)
1{
2 "id": 123,
3 "name": "Nested Folder",
4 "parent": {
5 "id": 50,
6 "name": "Parent 1",
7 "parent": {
8 "id": 10,
9 "name": "Parent 2"
10 ...
11 }
12 },
13 "children": { "count": 0 },
14 "files": { "count": 3 },
15 ...
16}Errors
400 Bad Request– invalid or missing ID.404 Not Found– folder not found.
Update Folder
Update an existing folder’s name and/or parent.
1PUT {STRAPI_BASE_URL}/api/media/folders/:id
2Content-Type: application/jsonPath Parameter
id(integer) — required.
Request Body
1{
2 "name": "Renamed Folder",
3 "parentId": 999
4}Response (200)
1{
2 "id": 123,
3 "name": "Renamed Folder",
4 "parent": 999,
5 ...
6}Errors
400 Bad Request– validation failure.404 Not Found– folder doesn’t exist.
Delete Folder
Delete a single folder.
1DELETE {STRAPI_BASE_URL}/api/media/folders/:idPath Parameter
id(integer) — required.
Response (200)
1[
2 {
3 "id": 123,
4 "name": "Deleted Folder",
5 ...
6 }
7]Bulk Delete
Delete multiple files and folders in one call.
1POST {STRAPI_BASE_URL}/api/media/bulk-delete
2Content-Type: application/jsonRequest Body
1{
2 "fileIds": [1, 2, 3],
3 "folderIds": [10, 11, 12]
4}Response (200)
1{
2 "deletedFiles": [ { ... } ],
3 "deletedFolders": [ { ... }]
4}Bulk Move
Move multiple files and folders to a target folder.
1POST {STRAPI_BASE_URL}/api/media/bulk-move
2Content-Type: application/jsonRequest Body
1{
2 "fileIds": [1, 2, 3],
3 "folderIds": [10, 11, 12],
4 "targetFolderId": 99
5}Response (200)
1{
2 "movedFiles": [ { ... } ],
3 "movedFolders": [ { ... } ]
4}Get Folder Structure
Retrieve the entire nested folder tree.
1GET {STRAPI_BASE_URL}/api/media/folders-structureResponse (200)
1[
2 {
3 "id": 1,
4 "name": "Root",
5 "children": [
6 { "id": 2, "name": "Child A", "children": [ { ... } ] },
7 ...
8 ]
9 }
10]Media Files
Upload Media File
Upload a file to a folder.
1POST {STRAPI_BASE_URL}/api/media/files
2Content-Type: multipart/form-dataForm Data
file(file) — required.folderId(integer) — optional.alternativeText(string) — optional.caption(string) — optional.skipIfExist(string) — optional, will skip if there is already file existing with same filename, caption and alternativeText (no matter the folderId).
Response (200)
1{
2 "data": [
3 {
4 "id": 321,
5 "name": "image.png",
6 "url": "/uploads/image.png",
7 "folder": 99,
8 ...
9 }
10 ]
11}Update Media File
Update file metadata (name, alt text, caption, or folder).
1POST {STRAPI_BASE_URL}/api/media/files/:id
2Content-Type: application/jsonPath Parameter
id(integer) — required.
Request Body
1{
2 "name": "newname.png",
3 "alternativeText": "An example",
4 "caption": "Caption text",
5 "folderId": 99
6}Response (200)
1{
2 "data": {
3 "id": 321,
4 "name": "newname.png",
5 "alternativeText": "An example",
6 "caption": "Caption text",
7 "folder": 99,
8 ...
9 }
10}List Media Files
Retrieve files, with optional search by name, caption or alternativeText, and sorting.
1GET {STRAPI_BASE_URL}/api/media/files?name=some_term&sort=createdAt:descQuery Parameters
name(string) — optional, filter by filenamecaption(string) — optional, filter by captionalternativeText(string) — optional, filter by alternativeTextsort(string) — optional, repeatable. Format:field:asc|desc.
Response (200)
1[
2 {
3 "id": 42,
4 "name": "filename.png",
5 "alternativeText": "marketing_contributors_other_internal",
6 "caption": "some random caption",
7 "folder": {
8 "id": 159,
9 "name": "Base dir"
10 },
11 "createdAt": "2025-04-20T11:22:33.444Z",
12 ...
13 },
14]Get Media File
Get file metadata (name, alt text, caption, folder, etc).
1GET {STRAPI_BASE_URL}/api/media/files/:idPath Parameter
id(integer) — required.
Response (200)
1{
2 "data": {
3 "id": 321,
4 "name": "newname.png",
5 "alternativeText": "An example",
6 "caption": "Caption text",
7 "folder": 99,
8 "formats": {
9 ...
10 }
11 ...
12 }
13}Delete Media File
Delete a single media file.
1DELETE {STRAPI_BASE_URL}/api/media/files/:idPath Parameter
id(integer) — required.
Response (200)
1[
2 {
3 "id": 123,
4 "name": "Deleted File",
5 ...
6 }
7]Error Handling
- 400 Bad Request: validation errors, missing/invalid params.
- 404 Not Found: resource not found.
- 500 Internal Server Error: unexpected server error.
License
This project is licensed under the MIT.
Install now
npm install strapi-plugin-media-library-handler
Create your own plugin
Check out the available plugin resources that will help you to develop your plugin or provider and get it listed on the marketplace.