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)
- Chinese translation lost HOT 2
- Odd number generated every time a new entry is created
- Selecting multiple "Add relation" in a Collection Type too quickly causes the tab to become unresponsive.
- Typeof - date (ex: 01/01/2024) field decrements from the selected date
- [V4] TS Global Middleware not picked up HOT 3
- Single Type Leads To 404 NotFoundError HOT 1
- [BUG] [Strapi v5 Beta]`defPropValFN` is not a function HOT 2
- On npm run build getting issues regarding typscript in my Strapi project
- [v5] Cannot populate multiple relations to the same table using the REST API and Document Service API
- error while custom table migration to mysql
- On Initial Install Get "You don't have permission to access content error" when looking at User collection type until you refresh.
- [GraphQL] The `isDefault` field from the i18n plugin locale is missing in the `I18NLocale` GraphQL type
- admin_ui::Uncaught Error while adding component in dynamic zone HOT 1
- admin_ui::Uncaught Error while adding component in dynamic zone HOT 1
- webpack.DefinePlugin is not a constructor on yarn build
- Throw ApplicationError in lifecycles.ts doesn't show error in admin panel
- User cache is not cleared when logging out and logging in as a different user
- users aren't redirected to the /usecase page anymore after telemetry accepted
- Lifecycle hooks can't access previous values of components HOT 4
- Getting 'Error: EBUSY: resource busy or locked, unlink' while trying to upload media in media library in strapi v4.24.2
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.