sendgrid-parse-api-example icon indicating copy to clipboard operation
sendgrid-parse-api-example copied to clipboard

Inbound Google function parse attacment issue

Open simonwebdev000000001 opened this issue 6 years ago • 0 comments

Hi, i have an isuue with GF parsing attachment emails, i am not able even check if attachments was arrived, here is my nodejs function


app.post('', async function(req, res) {
 
  try {

    if (req.method === 'POST') {
      const busboy = new Busboy({ headers: req.headers, limits: 50000000 });
      const uploads = {};
      const body = {};


      busboy.on('field', (fieldname, val) => { 
        body[fieldname] = val;
      });
      const tmpdir = os.tmpdir();
      const fileWrites = [];
  
      busboy.on('file', (fieldname, file, filename) => {
        const filepath = path.join(tmpdir, filename); 
        uploads[fieldname] = {
          filename: filename || file.name || 'temp.temp',
          filepath,
          file,
        };

        const writeStream = fs.createWriteStream(filepath);
        file.pipe(writeStream);
 
        const promise = new Promise((resolve, reject) => {
          file.on('end', () => {
            writeStream.end();
          });
          writeStream.on('finish', resolve);
          writeStream.on('error', reject);
        });
        fileWrites.push(promise);
      });
 
      busboy.on('finish', () => {
        Promise.all(fileWrites).then(async () => { 
          try {

         //uploads always are empty
          } catch (e) {
            console.log(e);
          }
           
        });
      });
 

      busboy.end(req.rawBody || req.body);
    } else { 
      res.status(405).send({ error: 'ONLY POST' });
    }

    console.log('Start logging--', req.body);


  } catch (e) {
    console.log(e);
    res.status(400).send(e.message || e);
  }
});

Can you help to find out the issue?

simonwebdev000000001 avatar Sep 06 '19 19:09 simonwebdev000000001