Hi folks, wondering if anyone could help please… I had posted this a couple of days a go on another thread but had not seen a response yet.
Basically I can get a file via HTTP.get
(or node “response”) and then send to AWS S3… but I can’t read the file and must be doing something wrong with encoding or perhaps something more serious is messed up.
Anyway, please see details below.
Any help appreciated.
thanks
Continuing the discussion from Base64 encode an image from a URL on server :
@mrzafod @nxcong @ccuilla Thanks for sharing this… I am trying to do something similar on the server (see below).
The file uploads to s3 but when I upload a PDF the browser says invalid PDF.
Any ideas/direction, please ?
var resultA = request.getSync(attachments[i].url, paramsA);
if (resultA.response){
var randomFileName = Random.id();
var fileBuf = new Buffer(resultA.response.body,'binary').toString('base64')
console.log("Random file:",randomFileName, resultA.response.headers["content-type"]);
var params = {Bucket: 'mybucket', Key: randomFileName, Body:fileBuf ,ContentType:resultA.response.headers["content-type"] };
var getParams = {Bucket: 'mybucket', Key: randomFileName};
var url = s3.getSignedUrl('getObject', getParams);
s3.upload(params, function(err, data) {
if (err) {
console.log("Error uploading data: ", err);
} else {
console.log("Successfully uploaded data to myBucket/myKey");
}
});
}
The response headers I get from “request” are:
So not sure if I have to do something special for this… eg “chunked”?