大佬教程收集整理的这篇文章主要介绍了node.js – aws lambda如何在S3中存储通过https检索的图像,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
var AWS = require('aws-sdk'); var https = require('https'); var Readable = require('stream').Readable; var s3 = new AWs.S3(); var fs = require('fs'); var url = 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/1d/AmazonWebservices_logo.svg/500px-AmazonWebservices_logo.svg.png'; exports.handler = function(event,context) { https.get(url,function(responsE) { var params = { Bucket: 'example',Key: 'aws-logo.png',Body: response // fs.createReadStream(responsE); doesn't work,arg should be a path to a file... // just putTing response errors out with "CAnnot determine length of [object Object]" }; s3.putObject(params,function(err,data) { if (err) { console.error(err,err.stack); } else { console.log(data); } }); }); };@H_197_8@
响应不包含文件的内容,而是包含http响应(包含其状态代码和标头).
你可以尝试这样的事情:
var AWS = require('aws-sdk'); var https = require('https'); var s3 = new AWs.S3(); var url = 'https://upload.wikimedia.org/wikipedia/commons/thumb/1/1d/AmazonWebservices_logo.svg/500px-AmazonWebservices_logo.svg.png'; exports.handler = function(event,function(res) { var body = ''; res.on('data',function(chunk) { // Agregates chunks body += chunk; }); res.on('end',function() { // Once you received all chunks,send to S3 var params = { Bucket: 'example',Body: body }; s3.putObject(params,data) { if (err) { console.error(err,err.stack); } else { console.log(data); } }); }); }); };@H_197_8@
以上是大佬教程为你收集整理的node.js – aws lambda如何在S3中存储通过https检索的图像全部内容,希望文章能够帮你解决node.js – aws lambda如何在S3中存储通过https检索的图像所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。