Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

add validation in strapi

async uploadFiles(ctx) {
    const {
      state: { userAbility, user },
      request: { body, files: { files } = {} },
    } = ctx;

    const uploadService = strapi.plugins.upload.services.upload;
    const pm = strapi.admin.services.permission.createPermissionsManager(
      userAbility,
      ACTIONS.create,
      fileModel
    );

    if (!pm.isAllowed) {
      throw strapi.errors.forbidden();
    }

    const data = await validateUploadBody(body);
    // ----------------------------------------
    // here I do some validation before the upload process.
    // throw strapi.errors.badRequest('');
    let validationFail = true;
    if (validationFail) {
      throw strapi.errors.badRequest('WRONG SIZE!!11');
    }
    // ----------------------------------------
    const uploadedFiles = await uploadService.upload({ data, files }, { user });

    ctx.body = pm.sanitize(uploadedFiles, { action: ACTIONS.read, withPrivate: false });
  },
Comment

PREVIOUS NEXT
Code Example
Javascript :: saving some fields of an instance in sequelize 
Javascript :: select not input elements text JS 
Javascript :: Replacing Specific word from url, replacing url 
Javascript :: add atribut readonly on form js 
Javascript :: go-gitea/gitea 
Javascript :: Get 7 days Array 
Javascript :: how to return a value to the parent function from ajax javascript 
Javascript :: js check if field in database is true or false 
Javascript :: Adding Handlers to All Forms 
Javascript :: shopify functions nodejs 
Javascript :: Das komplette JavaScript in den Footer laden 
Javascript :: useLinkPressHandler 
Javascript :: Cannot resolve name `object`.Flow 
Javascript :: firebase messaging service not working with electron 
Javascript :: functional-javascript-workshop solutions 
Javascript :: put validation on the cell number in angular 
Javascript :: loose and strict equality 
Javascript :: jquery replacechild 
Javascript :: how to route with credentials react 
Javascript :: how to add class to only one selected row then remove it after selecting it again 
Javascript :: como tanformar um paraafrafo para maiusculaavascript 
Javascript :: how can i add + buttons for expand and - button for collapse in react 
Javascript :: resource loads fastest 
Javascript :: javascript intersection reduce, filter, includes 
Javascript :: next-pwa push notification 
Javascript :: why android folder size is 500mb in react native 
Javascript :: javascript is even 
Javascript :: Rest and spread operators in ES6 
Javascript :: invert binary tree js 
Javascript :: Replace all ocourrences in JS 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =