0

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 !

Progman
  • 16,827
  • 6
  • 33
  • 48
Benjamin Merchin
  • 1,029
  • 6
  • 11

1 Answers1

3

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

dziraf
  • 3,607
  • 1
  • 16
  • 22