Har*_*rry 3 amazon-s3 node.js express knox-amazon-s3-client
当请求进入页面时,例如app.get("/")我想从amazon s3返回静态HTML页面.我知道我可以从S3请求它然后发送它,但这似乎很慢.反正有没有告诉请求者直接从s3获取文件而不更改URL?
谢谢.
如果做不到这一点,从s3提供文件的最快方式是什么?
本教程首先介绍如何编写文件
http://www.hacksparrow.com/node-js-amazon-s3-how-to-get-started.html
// We need the fs module so that we can write the stream to a file
var fs = require('fs');
// Set the file name for WriteStream
var file = fs.createWriteStream('slash-s3.jpg');
knox.getFile('slash.jpg', function(err, res) {
res.on('data', function(data) { file.write(data); });
res.on('end', function(chunk) { file.end(); });
});
Run Code Online (Sandbox Code Playgroud)
有没有办法发送文件而不先写它?写它看起来非常慢.
Lau*_*rin 11
如您所料,您无法在不更改URL的情况下直接从S3获取请求者.您必须代理远程页面:
var http = require('http'),
express = require('express'),
app = express();
app.get('/', function(req, res) {
http.get('http://www.stackoverflow.com', function(proxyRes) {
proxyRes.pipe(res);
});
});
app.listen(8080);
Run Code Online (Sandbox Code Playgroud)
您可以缓存远程页面以获得更好的性能.
| 归档时间: |
|
| 查看次数: |
3128 次 |
| 最近记录: |