0

I am working on AWS with box api. I want to upload the file to s3 bucket using the lambda function. but giving the errors

I am using this api https://developer.box.com/en/reference/get-files-id-content/ to get the content of the file and upload to s3 bucket. But contents are in stream.

Below is my code

 let status= await  appUserClient.files.getReadStream(fileId, null, async function(error, stream) {
     var params = {Bucket: 'bucketname', Key: 'key.csv', Body: stream};
      let status= await s3.upload(params, function(err, data) {
          if (err) {
              console.log(err);
            return 0;
          }else{
               console.log(data);
              return 1;
          }
      }).promise();
});

1 Answer 1

1

You can try this way

You need

const stream = require('stream');



   function uploadFromStream(s3) {
     var pass = new stream.PassThrough();

     var params = {Bucket: BUCKET, Key: KEY, Body: pass};
     s3.upload(params, function(err, data) {
        console.log(err, data);
     });

     return pass;
}

Now you can use it

appUserClient.files.getReadStream(fileId, null,function(error, stream){

    if(error){
       console.log(error)
      }
    else{
      stream.pipe(uploadFromStream(s3))
     }
 });
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your connect! but giving the error stream is undefined
you did not get stream while getReadStream??
var pass = new stream.PassThrough(); this line giving the error
ooh ok const stream = require('stream'); you need this..update the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.