如何避免Google关于文件的警告可能很危险

时间:2019-08-29 11:50:29

标签: node.js

我正在将zip文件从服务器发送到客户端,但是当文件已下载时,google会显示错误消息,表明该文件可能很危险,可能是因为该文件包含.js文件。有什么方法可以解决此问题。

问题:Image of the Problem

function zipDirectory(source, out) {

 const archive = archiver('zip', { zlib: { level: 9 }});
 const stream = fs.createWriteStream(out);

return new Promise((resolve, reject) => {
archive
  .directory(source, false)
  .on('error', err => reject(err))
  .pipe(stream)
;

stream.on('close', () => resolve(console.log('file compressed to zip')));
archive.finalize();

});
};
app.get('/site/:url/download', async(req,res) => {
console.log('get me');
await zipDirectory(path,zipPath);

res.writeHead(200, {
'Content-Type': 'application/zip',
'Content-disposition': `attachment; filename=${zipPath}`
});
const readStream = fs.createReadStream(zipPath);

        readStream.on('open', function() {

          readStream.pipe(res);
});
readStream.on('error', function(err) {
res.end(err);
});


});

0 个答案:

没有答案