【发布时间】:2016-09-20 21:38:51
【问题描述】:
我有一个服务器通过 PUT 接收文件,然后将它们存储在 S3 中。
在客户端 PUT 文件后,它通常会立即请求它们以换取渲染。不幸的是,我的服务器需要一些时间来实际处理上传并将它们存储在 S3 中。
这是我在 Express 中使用的代码:
req.pipe(writeStream);
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'PUT, OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type');
if ('OPTIONS' === req.method) {
res.sendStatus(200);
res.end('OK!');
return;
}
if ('PUT' === req.method) {
writeStream.on('error', () => {
res.sendStatus(500);
});
writeStream.on('close', async () => {
// This might take 30s
await this.storage.store(fn, args.blobID);
// This does not seem to have any effect
// I would like to prevent the client from 'finishing' the
// PUT request before I say it is done.
res.end('OK!')
});
res.sendStatus(200);
}
理想情况下,我可以“暂停”客户的 PUT 请求,直到 storage.store() 完成,确保文件实际可用。
有什么办法可以做到吗?
另外,我不确定sendStatus() / end() 电话,如果我混淆了,请随时发表评论。
附:我知道,在理想情况下,我只会分发签名的 URL,让客户端直接上传到 S3,但我需要 AES256 加密......
【问题讨论】:
标签: http express browser amazon-s3