我正在测试streaming-s3软件包,并试图从request.get上传基本教程
。目前,它一直卡住,永远不会启动、崩溃或任何事情......
我的代码 :
var elem = list.shift();
console.log(elem._id+" "+elem.main_img); //elem contains exactly what it should
var rStream = request.get(elem.main_img);
uploader = new StreamingS3(rStream, {accessKeyId:'XXXXXX', secretAccessKey:'XXXXXXX',region:"eu-west-1"},
{
Bucket: 'xxxxxx-myimages',
Key: elem._id,
ContentType: 'image/jpeg',
ACL:'public-read'
},
{
concurrentParts: 2,
waitTime: 10000,
retries: 1,
maxPartSize: 10*1024*1024,
}
);
uploader.begin(); // important if callback not provided.
uploader.on('data', function (bytesRead) {
console.log(bytesRead, ' bytes read.');
}).on('part', function (number) {
console.log('Part ', number, ' uploaded.');
}).on('uploaded', function (stats) {
console.log('Upload stats: ', stats);
}).on('finished', function (resp, stats) {
console.log('Upload finished: ', resp);
}).on('error', function (e) {
console.log('Upload error: ', e);
});
它基本上是一个复制粘贴,填有空白...什么可能导致它不起作用并且不显示任何输出?我检查了请求,它回复了 200 状态代码。控制台.log上传器显示所有内容都已正确填充...
您确定所有内容都设置在该列表中吗?这是我刚刚上传的文件的控制台输出:
node temp
123 http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=3c6263c3453b
16902 ' bytes read.'
2543 ' bytes read.'
Part 1 uploaded.
Upload stats: { downloadSpeed: Infinity,
uploadSpeed: 9722500,
downloadTime: 0,
uploadTime: 2,
size: 19445 }
Upload finished: { Location: 'https://zlatko-test.s3.amazonaws.com/123',
Bucket: 'zlatko-test',
Key: '123',
ETag: '"de7139567df95ed9dacadfc5a3a1317c-1"' }
以下是我修改您的文件的方式,基本上添加一个静态元素并更改要从我的 shell 中获取的访问信息:
var list = [{main_img: 'http://cdn.sstatic.net/stackoverflow/img/sprites.png?v=3c6263c3453b', _id: '123'}];
var request = require('request');
var StreamingS3 = require('streaming-s3');
var elem = list.shift();
console.log(elem._id+" "+elem.main_img); //elem contains exactly what it should
var rStream = request.get(elem.main_img);
uploader = new StreamingS3(rStream, {accessKeyId:process.env.S3_ACCESS_KEY, secretAccessKey:process.env.S3_SECRET,region:process.env.S3_REGION},
{
Bucket: process.env.S3_BUCKET,
Key: elem._id,
ContentType: 'image/jpeg',
ACL:'public-read'
},
{
concurrentParts: 2,
waitTime: 10000,
retries: 1,
maxPartSize: 10*1024*1024,
}
);
uploader.begin(); // important if callback not provided.
uploader.on('data', function (bytesRead) {
console.log(bytesRead, ' bytes read.');
}).on('part', function (number) {
console.log('Part ', number, ' uploaded.');
}).on('uploaded', function (stats) {
console.log('Upload stats: ', stats);
}).on('finished', function (resp, stats) {
console.log('Upload finished: ', resp);
}).on('error', function (e) {
console.log('Upload error: ', e);
});
你在窗户上什么的?