node.jsadminjs

AdminJS call backend from component with arguments


I am trying to call an action with arguments from an AdminJS component. I am uploading files to aws s3.

There is the api.resourceAction method that works well for me to call a resource action, but I need to send some strings to the action, is there a more simple way or I have to use fetch with a custom route ? (this is what I am currently using and it works but it is overcomplicated)

Thanks !


Solution

  • You can use either params or data.

    AdminJS ApiClient is just an extension of Axios where resourceAction, recordAction etc are wrappers around Axios API. So what you can do:

    api.resourceAction({
      // resourceId and actionName are required by "resourceAction"
      resourceId: 'Image',
      actionName: 'upload',
      // you can add any valid Axios config option too
      params: {
        someParam: 'test'
      },
      data: {
        file: <your file>
      },
      method: 'post'
    })
    

    params will be available in request.query, data will be available in request.payload of your handler function