Mic*_*vel 2 upload gzip amazon-s3 node.js
我有一个 node.JS 程序,它从 Redis 读取字符串数组。我需要将此字符串以 GZIP 格式上传到 AWS s3 中的存储桶中,而无需在上传之前在本地创建 gzip 文件。
基本上,我想将读取的字符串从 Redis 流式传输到压缩的 s3 存储桶 gzip。
除了上述问题,我想知道以这种方式进行编程的有效和推荐方式是什么,因此将存储在 S3 中的文件最大为 64 MB,如果有额外的数据,额外的文件已创建(也限制为最大 64MB)。在下面的示例中,我展示了如何从 Redis 键读取要存储在 s3 gzip 中的值限制为 64 MB:
client.lrange(key, 0, -1, (error, arrayStringValue) => {
if (arrayStringValue == null || !arrayStringValue.length) {
client.del(key);
return console.log("removing key, no values");
}
if (error) reject(error);
console.log("finish iterating");
impressionsRecorded = true;
//compress
uploadToS3(arrayStringValue, "bucket/key", null);
Run Code Online (Sandbox Code Playgroud)
基本上我缺少的是uploadToS3方法的正确实现
Jay*_*Jay 10
我不得不解决同样的问题。这是我在 Node.js 中的解决方案。
const zlib = require('zlib');
const uncompressedString = 'Hi there';
const compressedStringAsBuffer = zlib.gzipSync(uncompressedString);
const AWS = require('aws-sdk');
const s3 = new AWS.S3();
const s3Params = {
Bucket: 'my-bucket',
Body: compressedStringAsBuffer,
Key: 'my-compressed-string.txt.gzip', // .gzip isn't required
ContentType: 'text/plain', // change the ContentType if you want to serve HTML, CSS, JS, etc.
ContentEncoding: 'gzip' // that's important
};
await s3.putObject(s3Params).promise();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2891 次 |
| 最近记录: |