Есть ли простой код для загрузки файла, который находится в форме, где много ввода типа = "текст"? - PullRequest
0 голосов
/ 30 апреля 2020

Вот. e js Файл с именем sendEmail.e js. html Код:

На самом деле мне нужно отправить электронное письмо, но не беспокойтесь о том, что мне просто нужно иметь возможность получить входные значения и загрузить файл на отправить форму .

Я использую Nodejs и модуль Formidale.

<form action="/sendMail" method="post" enctype="don't know what to put
   her">   
      <div>
         <input type="text name="message"></input>
         <input type="text name="subject"></input>
 <!-- the file is down here -->
         <input type="file" class="form-control-file" name="filetoupload">
         <input type="submit" name="myFile" value="send">
      </div> 
</form>

js Код в моем приложении. js файл на стороне сервера в моем проекте Nodejs:

  app =express();
    app.listen(8080, () => {
      console.log('listening on 8080');
    });

    app.post("/sendEmail", (req, res, next) => {
    var id_file = "A unique Id that I will set later";
    var form = new formidable.IncomingForm();
    form.parse(req, function (err, fields, files) {
    var newpath = 'C:/Users/Stéphanie/EBWP/public/files/' + id_file;
    fs.rename(oldpath, newpath, function (err) {
    if (err) throw err;
    });
    })
    mailOptions.subject= req.body.subject;
    mailOptions.text= req.body.message;
    mailOptions.attachments["filename"] = 'SCAN_req.body.clientEmail'+'.pdf';
    mailOptions.attachments["path"] = "public/scans/"+id_file;

    transporter.sendMail(mailOptions, function(error, info){
         if (error) {
            console.log(error);
            } else {
            console.log('Email sent: ' + info.response);
            }
      });
    });
...