Trying to upload data stream in Amazon S3

0 votes

I tried to push a QR code of SVG to S3 from my node application.
I believe I should be uploading a Buffer to S3. Whenever I try to inspect the qrResult, I don't get to see one anywhere. 
Guess I'm fundamentally poor with the concept of writeStreams, and how should I pipe the data to an S3 upload, I am not able to resolve this, tried several times. This is what I am using there: 

let fileName = 'qrCode'

let qrCode = Qr.image('The ultimate test', { type: 'svg' }); 
let output = fs.createWriteStream(fileName)
let qrResult = qrCode.pipe(output)


let s3bucket = new Aws.S3({
   accessKeyId: env.AWS_ACCESS_KEY
   secretAccessKey: env.AWS_SECRET,
   Bucket: env.S3_BUCKET_NAME,
});

let params = {
   Bucket: env.S3_BUCKET_NAME,
   Key: fileName,
   Body: qrResult,
 };

s3bucket.upload(params, function (err, qrResult) {
   if (err) {
     console.log('error in callback');
     console.log(err);
   }

   console.log('success');
   console.log(qrResult);
});

Can anyone help me with this? 

Jun 28, 2018 in AWS by Hammer
• 360 points
2,323 views

1 answer to this question.

0 votes

Try adding the ContentType & ACL in your params like this:

let params = {
  Bucket: env.S3_BUCKET_NAME,
  Key: fileName,
  Body: qrResult,
  ContentType: 'image/svg+xml',
  ACL: 'public-read'
};

Also, I can't see file object in your code.

Also, use putObject rather than upload like:

s3bucket.putObject(params... 
//(Try using the above type of syntax)
answered Jun 28, 2018 by Cloud gunner
• 4,670 points

Related Questions In AWS

0 votes
1 answer

How to upload an object into Amazon S3 in Lambda?

I suspect you are calling the context.done() function before s3.upload() has ...READ MORE

answered Sep 27, 2018 in AWS by Archana
• 4,170 points
938 views
0 votes
1 answer

How to upload a file to Amazon S3 without passing it my server?

This article pretty much explains the entire ...READ MORE

answered Aug 14, 2018 in AWS by Archana
• 4,170 points
3,008 views
0 votes
1 answer

How to upload a lib for Tomcat in Amazon EC2?

You need to set the proper privileges ...READ MORE

answered Aug 20, 2018 in AWS by Archana
• 4,170 points
693 views
0 votes
1 answer

In Amazon Data Pipeline, how to make sure only once instance of a pipeline is running at any time?

On the CopyTablesActivity, you could set a lateAfterTimeout attribute ...READ MORE

answered Sep 19, 2018 in AWS by Priyaj
• 58,090 points
1,924 views
+1 vote
2 answers

AWS CloudWatch Logs in Docker

The awslogs works without using ECS. you need to configure ...READ MORE

answered Sep 7, 2018 in AWS by bug_seeker
• 15,520 points
1,692 views
+2 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 58,090 points
2,426 views
+1 vote
1 answer
0 votes
1 answer

Trying to use GetApiKeys in Amazon SDK

Try using this one:  var client = new ...READ MORE

answered Jun 12, 2018 in AWS by Cloud gunner
• 4,670 points
890 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP