Comments (2)
Can you please feel out reproduction steps.
from strapi.
To reproduce the bug you can extend @strapi/plugin-upload. The bug is in the version 4.24.2 of the plugin.
src/extensions/upload/overrides.ts
/**
* Overriding enhanceAndValidateFile method to validate available file extensions
* node_modules/@strapi/plugin-upload/server/services/upload.js
*/
import { errors } from '@strapi/utils';
import fs from 'fs';
const { ApplicationError } = errors;
const allowedExtensions = [
'.jpg',
'.jpeg',
'.png',
'.webp',
'.svg',
'.pdf',
'.mp4',
];
const isFileExtensionAllowed = (fileExtension) => {
return allowedExtensions.includes(fileExtension);
};
export async function enhanceAndValidateFile(file, fileInfo = {}, metas = {}) {
// @ts-expect-error this will be available on override
const currentFile = await this.formatFileInfo(
{
filename: file.name,
type: file.type,
size: file.size,
},
fileInfo,
{
...metas,
tmpWorkingDirectory: file.tmpWorkingDirectory,
}
);
if (!isFileExtensionAllowed(currentFile?.ext)) {
throw new ApplicationError(
`File type is not allowed. Allowed extentions: ${allowedExtensions.join(
','
)}`
);
}
currentFile.getStream = () => fs.createReadStream(file.path);
const { optimize, isImage, isFaultyImage, isOptimizableImage } = strapi
.plugin('upload')
.service('image-manipulation');
if (await isImage(currentFile)) {
if (await isFaultyImage(currentFile)) {
throw new ApplicationError('File is not a valid image');
}
if (await isOptimizableImage(currentFile)) {
return optimize(currentFile);
}
}
return currentFile;
}
src/index.ts
import { enhanceAndValidateFile } from './extensions/upload/overrides';
export default {
register({ strapi }) {
/**
* Overriding enhanceAndValidateFile function to validate available file extensions
*/
strapi.plugin('upload').service('upload').enhanceAndValidateFile =
enhanceAndValidateFile;
},
};
With this configuration, I get an error `throw new ApplicationError('File is not a valid image') ' when trying to upload an image to the media library. ' Everything worked with the plugin's 4.24.1 version.
from strapi.
Related Issues (20)
- Command plugin:init is missing file HOT 4
- Strapi transfer CLI connects to ipv6 localhost HOT 1
- Unexpected notification in Settings -> Overview HOT 2
- Strapi 4 Following Contributing Guide to run custom fork of strapi with admin panel changes does not work with localhost:4000 HOT 1
- Nodemailer provider throws a Connection timeout HOT 1
- Controller base methods must be not undefined.
- [v5] Using pagination query params at root level of query returns incorrect error
- DTS Import is failing on schema detection HOT 6
- Clicking on Load More button for Relations Shows ID's of Entries instead of the Selected Entry Title HOT 1
- Entity actions are not appeared in Content manager list view
- DTS Import Unique Constraint Failed HOT 2
- [Strapi v5 Beta] Endless Loading While Running The Build
- [Strapi v5 Beta] API Returns 404 for Invalid Requests and Asset Deletion on Dashboard
- too many terms in compound SELECT, when relating over 500 items.
- Referring to a Collection Type, Selecting right side collection type dropdown appears behind the dialog box
- "No permissions to see this field" randomly on relations and media asset fields
- i18n locale overrides other locales HOT 2
- Single types sometimes crash the app HOT 3
- Date picker not displaying the right date when selecting one HOT 1
- updateMany() doesn't work with relations field. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from strapi.