title: API gateway returning corrupted excel file
body: <p>My API end point returns an excel file streamed from S3. It works on the local but when testing on API gateway the file is corrupted. Here is my API code:</p>
  
  <pre><code>const downloadContentFromS3 = async function(bucket, file) {
    return new Promise((resolve, reject) =&gt; {
      streamFileFromS3(bucket, file, (error, s3buffer) =&gt; {
        if (error) return reject(error);
        return resolve(s3buffer);
      });
    });
  };
  
  const streamFileFromS3 = async function(bucket, fileName, callback) {
    const params = {
      Bucket: bucket,
      Key: fileName,
    };
  
    const buffers = [];
    const stream = s3.getObject(params).createReadStream();
    stream.on('data', data =&gt; buffers.push(data));
    stream.on('end', () =&gt; callback(null, Buffer.concat(buffers)));
    stream.on('error', error =&gt; callback(error));
  };
  
  downloadExcelFile: async (req, res) =&gt; {
    try {
      const fileName = 'myFilename';
      const workbook = await downloadContentFromS3(
        'bucket-name'        
        fileName
      );
      const workbook = xlsx.read(buffer);
  
      res.setHeader('Content-disposition', `attachment; filename=${fileName}`);
      res.setHeader(
        'Content-type',
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
      );
      const wbout = xlsx.write(workbook, { bookType: 'xlsx', type: 'buffer' });
      res.status(200).send(Buffer.from(wbout));
    } catch (error) {
      throw new OriolaError(error.message);
    }
  },
  </code></pre>
  
  <p><strong>What I have tried so far:</strong>  Setup the binary media types as shown in the picture:<a href="https://i.stack.imgur.com/MlU7k.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MlU7k.png" alt="enter image description here"></a></p>
  
  <p>In addition tried to set the <strong>RESPONSE HEADER</strong> to Content-Type and Content-Disposition but to no avail. The problem seems to persist. Any ideas and help is appreciated.</p>
  
  <p><strong>EDIT:</strong> I have also tried to set binary type <code>*/*</code> in the settings but this does not help as well. </p>