node.js
에 is가 생성 된 직후에 pdf를 삭제하려고합니다. 생성 된 pdf는 전자 메일 첨부 파일로 전송되어 dropbox
에 업로드 된 다음 로컬 파일 시스템에서 삭제됩니다. 하지만 삭제하려고하면 삭제되지 않으며 이메일도 보내지 않습니다. pdf는 html-pdf
을 사용하여 생성됩니다. 내가 할 때 파일이 이미 작동하지만, 경우에 따라서 fs.unlink' or
fs.unlinkSync`가, 경로로 생성되는 파일이 삭제되지 않습니다Nodejs 생성 된 파일 즉시 삭제
if (result) {
var filename = user.number+ ".pdf";
var path = './public/files/'+filename ;
var options = { filename: path, format: 'Legal', orientation: 'portrait', directory: './public/files/',type: "pdf" };
html = result;
pdf.create(html, options).toFile(function(err, res) {
if (err) return console.log(err);
console.log(res);
});
var dbx = new dropbox({ accessToken: mytoken });
fs.readFile(path,function (err, contents) {
if (err) {
console.log('Error: ', err);
}
dbx.filesUpload({ path: "/"+filename ,contents: contents })
.then(function (response) {
console.log("done")
console.log(response);
})
.catch(function (err) {
console.log(err);
});
});
var mailOptions = {
from: 'xyz', // sender address
to: user.email, // list of receivers
subject: 'Confirmation received', // Subject line
attachments : [{
filename: filename,
path : path
}]
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Message %s sent: %s', info.messageId, info.response);
});
fs.unlinkSync(path); // even tried fs.unlink , does not delete file
// fs.unlinkSync(someother file); this one works
}
: 여기 내 코드입니다.
당신은 이메일을 전송 완료 될 때까지 기다릴 필요가 ..해야한다. – SLaks
console.log가 가장 친한 친구입니다.'unlinkSync (path)'대신에 무엇인가를 출력하면 –