我有一个字符串templateString
正在发布到Express中的路由。如何将此字符串作为HTML文件流式传输并下载到客户端?
res.setHeader('Content-type', 'text/html');
res.setHeader('Content-disposition', `attachment; filename=${testname}.html`);
^^这会强制浏览器下载。
如何获取请求中的字符串并以HTML文件的形式将其传递给客户端?
答案 0 :(得分:1)
我认为您可以使from selenium.webdriver.chrome.options import Options
dir_path = os.path.dirname(os.path.realpath(__file__))
chromedriver_path = os.path.join(dir_path, "chromedriver")
options = Options()
options.binary_location = "/app/.apt/usr/bin/google-chrome-stable"
driver = webdriver.Chrome(executable_path = chromedriver_path, chrome_options = options)
形成字符串并通过Buffer
方法发送。
res.end
您可以阅读有关let file = Buffer.from('Your string', 'utf8');
res.writeHead(200, {
'Content-Type': 'text/html',
'Content-disposition': `attachment; filename=${testname}.html`,
'Content-Length': file.length
});
res.end(file);
here
答案 1 :(得分:0)
想出来.. 这最后一条简单的线似乎有用..
res.setHeader('Content-type', 'text/html');
res.setHeader('Content-disposition', `attachment; filename=${testname}.html`);
res.end(req.body.templateString);