我想将远程pdf文件上传到s3服务器。
我正在使用streaming-s3包。虽然它适用于其他网站但不适用于特定网站。(https://arxiv.org/pdf/1611.10012.pdf)
当我尝试从https://arxiv.org网站上传pdf文件时,它无法在s3服务器上传。
这是我将pdf文件上传到s3服务器的代码
var streamingS3 = require('streaming-s3');
var awsHeader = {
Bucket: bucket,
Key: '1611.10012.pdf',
ContentType: 'application/pdf',
ACL: 'public-read'
};
var url = "https://arxiv.org/pdf/1611.10012.pdf";
var fileReadStream = request.get(url);
console.log("parsing url : " + url);
uploadFile(fileReadStream, awsHeader, cb);
var uploadFile = function (fileReadStream, awsHeader, cb) {
//set options for the streaming module
var options = {
concurrentParts: 2,
waitTime: 20000,
retries: 2,
maxPartSize: 10 * 1024 * 1024
};
//call stream function to upload the file to s3
var uploader = new streamingS3(fileReadStream, config.aws.accessKey, config.aws.secretKey, awsHeader, options);
//start uploading
uploader.begin();// important if callback not provided.
// handle these functions
uploader.on('data', function (bytesRead) {
//console.log(bytesRead, ' bytes read.');
});
uploader.on('part', function (number) {
//console.log('Part ', number, ' uploaded.');
});
// All parts uploaded, but upload not yet acknowledged.
uploader.on('uploaded', function (stats) {
//console.log('Upload stats: ', stats);
});
uploader.on('finished', function (response, stats) {
console.log(response);
cb(null, response);
});
uploader.on('error', function (err) {
console.log('Upload error: ', err);
cb(err);
});
};
我也试过这个网站的其他代码,但它也没有将文件上传到s3服务器。
var options = {
url: 'https://arxiv.org/pdf/1611.10012.pdf',
headers: {
'Referer': 'https://arxiv.org',
'User-Agent': 'stagefright/1.2 (Linux;Android 5.0)'
}
}
request(options, function (error, response, body) {
console.log('error:', error);
console.log('statusCode:', response && response.statusCode);
uploadFile(body, awsHeader, cb);
});
任何想法为什么s3上传不适用于特定网站(https://arxiv.org/pdf/1611.10012.pdf)?