70
Support for media folders in the content API
D
Derrickmehaffy
With the upcoming release of Strapi v4.3.0 and Media folders, the content API will not be able to utilize them. For those that believe it would be a good addition to also have folders at the content API level please leave a vote and comment what your use case would be.
Tais993
At my work we're talking about thousands of images, currently they're structured in many many folders.
With the API, we can only upload to that 1 folder..
That removes the whole benefit of using the API, having thousands of images with some the same name, in the same folder, nah.
This would be extremely appreciated, otherwise we'll have to stick with Umbraco.
Ayodeji Alarape
Here's a plugin I developed that could help, It can get folders and files in the folder aswell.
Cameron McBroom
I found clients can get confused having to link/create relations to different images or files when there are multiple galleries throughout the site. I think it is much more intuitive for a non dev to just put their photos into different folders and they will appear in the corresponding galleries.
For now I have just made a simple get by folder id controller like so. Not ideal but works
module.exports = {
getByFolderId: async (ctx, next) => {
try {
const files = await strapi.db.connection
.select('*')
.from('files')
.innerJoin('files_folder_links', 'files.id', 'files_folder_links.file_id')
.where('folder_id', folderId)
ctx.body = files
} catch (err) {
ctx.body = err;
}
}
};
Axel Hultman
This would be a great feature. As others have mentioned, why not provide the options you get in the plugins own methods and add the ability to specify folder. Need to create custom controllers just to adjust this now
Lucas S.
Having the ability to dynamically create folders on upload would make migrations so much easier. Imagine a structure with hundreds of folders organized by a client and we have to keep that same structure on the admin UI. Automation would be a breeze, it is a quality of life feature.
Tobias
Here a solution that uses the upload plugin's own methods:
// Generate folders
async createFolders(order) {
// Create year media folder if not exists
const year = new Date().getFullYear().toString()
let yearFolder = await strapi.query('plugin::upload.folder').findOne({where: {name: year}});
if (!yearFolder) {
await strapi.plugins.upload.services.folder.create({name: year})
yearFolder = await strapi.query('plugin::upload.folder').findOne({where: {name: year}});
}
// Create order media folder
await strapi.plugins.upload.services.folder.create({name: order, parent: yearFolder.id})
return await strapi.query('plugin::upload.folder').findOne({where: {name: order, parent: yearFolder}});
},
// Move files into folder
async moveOrderFilesToFolder(order, folder) {
let update = []
const files = (await strapi.db.query("api::order.order").findOne({
where: { id: order.id },
populate: {
files: true,
}
})).files
if(files !== null) {
for (const file of files) {
update.push(await strapi.plugins.upload.services.upload.updateFileInfo(file.id, {
name: file.name,
alternativeText: file.alternativeText,
caption: order.attributes.order,
folder: folder.id,
folderPath: folder.path
}))
}
return update
}
},
A
Alagunasalahaddin
In our case, we are trying to automatize our folders so all our clients can have a lead of how they must to work with the media library.
All of this is from the backend.
Tobias
push
Tobias
gu-stav any update on this?
Would be sufficient to be able to additionaly define the folder in formData like this (no need to create the folder on the file system, it should just set the attribute in the database like the admin panel does):
<form>
<input type="text" name="folder" /> <!-- NEW -->
<input type="file" name="files" />
<input type="text" name="ref" value="api::restaurant.restaurant" />
<input type="text" name="refId" value="5c126648c7415f0c0ef1bccd" />
<input type="text" name="field" value="cover" />
<input type="submit" value="Submit" />
</form>
Rolf Veinø Sørensen
I would expect the public api to have the same abilities for the media library as the strapi admin interface does. This allows developers of websites to create a full features media browser/library with folders.
Load More
→