File upload from custom app

Hi,

I’m building an API that takes a JSON string from a Google Doc and returns an epub (ebook) file. I’m struggling with how to return the file in a way that Make.com expects.

My custom module’s interface is configured like this:

[
    {
        "name": "name",
        "type": "filename",
        "label": "Name",
        "semantic": "file:name"
    },
    {
        "name": "data",
        "type": "buffer",
        "label": "Data",
        "semantic": "file:data"
    }

]

So I tried returning data like this:

      const fileBuffer = await fs.promises.readFile(epubFilePath);
      
      return res.status(200).json({
        name: fileName,
        data: fileBuffer, 
      });

The API response looked like this:

Make.com didn’t recognize that as a buffer.

The I tried this:

// Read the file into a buffer
      const fileBuffer = await fs.promises.readFile(epubFilePath);

      // Calculate buffer metadata
      const size = fileBuffer.length; // Size of the buffer
      const checksum = this.calculateChecksum(fileBuffer); // Generate a checksum for the buffer
      const prefix = 'IMTBuffer';

      // Convert the buffer to a custom string format
      const hexData = fileBuffer
        .toString('hex')
        .match(/.{1,2}/g)
        ?.join('');
      const customFormattedData = `${prefix}(${size}, binary, ${checksum}): ${hexData}`;

      // Console log the first 100 characters of the custom formatted data
      console.log(customFormattedData.slice(0, 100));

      // Return the formatted data in JSON
      return res.status(200).json({
        name: fileName,
        data: customFormattedData, // Custom formatted buffer data
      });

Which returns the following:

Make.com recognizes this as “Buffer, codepage:binary” but when I save the file to Google Drive, it saves the string version of the uploaded data instead of the binary version. If I inspect the file contents on Google Drive, it looks like this:

IMTBuffer(39004, binary, 8a231bb2dda2943224ca8050830c8af8254bcd09): 504b03040a0000000000a7a3365a6f61ab2c1400000014000000080000006d696d65747970656170706c69636174696f6e2f657075622b7a6970504b0304140008000800a7a3365a000000000000000000000000160000004d4554412d494e462f636f6e7461696e65722e786d6c…

Any thoughts? I have read all of the documentation and forum posts that I can find but I can’t figure it out.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.