Skip to content

Inbound Google function parse attacment issue #3

@simonwebdev000000001

Description

@simonwebdev000000001

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions