Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for Media Library upload #5971

Merged
merged 12 commits into from
Jun 25, 2020
8 changes: 4 additions & 4 deletions packages/strapi-plugin-upload/services/Upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ const combineFilters = params => {

module.exports = {
formatFileInfo({ filename, type, size }, fileInfo = {}, metas = {}) {
const ext = '.' + mime.extension(type) || path.extname(filename);
const baseName = path.basename(filename, path.extname(filename));
const ext = path.extname(filename);
alexandrebodin marked this conversation as resolved.
Show resolved Hide resolved
const basename = path.basename(filename, ext);

const usedName = fileInfo.name || baseName;
const usedName = fileInfo.name || filename;
alexandrebodin marked this conversation as resolved.
Show resolved Hide resolved

const entity = {
name: usedName,
alternativeText: fileInfo.alternativeText,
caption: fileInfo.caption,
hash: generateFileName(usedName),
hash: generateFileName(basename),
ext,
mime: type,
size: bytesToKbytes(size),
Expand Down
2 changes: 2 additions & 0 deletions packages/strapi-plugin-upload/services/image-manipulation.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const generateThumbnail = async file => {
const { width, height, size } = await getMetadatas(newBuff);

return {
name: `thumbnail_${file.name}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the filename might be really strange here as it can be set by the user. What was the need for it here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name attribute should be set for all media files because it goes to the same handler for upload. A user can use file name as a property for a media library in custom plugin.
For example, to provide uniqueness of file names in a library. Only hash for this is not enough because it is random generated every time.

hash: `thumbnail_${file.hash}`,
ext: file.ext,
mime: file.mime,
Expand Down Expand Up @@ -121,6 +122,7 @@ const generateBreakpoint = async (key, { file, breakpoint }) => {
return {
key,
file: {
name: `${key}_${file.name}`,
hash: `${key}_${file.hash}`,
ext: file.ext,
mime: file.mime,
Expand Down