Skip to main content

Currently working on Zapier rest hook using Zapier CLI, the issue i’m facing is how to handle file when multipart/form-data is sent to the resthook target URL.

 

This is sample code, but i need the one to handle multipart.

https://github.com/zapier/zapier-platform/blob/main/example-apps/rest-hooks/triggers/recipe.js

 

Thank you

To accept multipart/form-data in a Zapier rest hook perform function, you need to use the req.files object. This object contains a list of all the files that were uploaded in the request.

To handle a file, you can use the req.files[filename] object. This object contains information about the file, such as its name, size, and type. You can use this information to save the file to your server or to upload it to another service.

Here is an example of how to handle a file in a Zapier rest hook perform function:

function perform(req, res, next) {
  const file = req.files.file;

  // Save the file to your server
  file.mv('/path/to/save/file.txt');

  // Upload the file to another service
  // ...
}

The sample code that you provided does not handle multipart/form-data. To handle multipart/form-data, you need to use the req.files object as shown in the example above.