1

I have a function that takes a stream as a parameter:

  startUpload(stream, filename) {
    const upload = this.s3.upload({
      Bucket: this.bucket,
      ServerSideEncryption: 'aws:kms',
      SSEKMSKeyId: this.s3SseKmsKeyId,
      Key: `${this.key}/${filename}`,
      Body: stream
    }, { partSize: 50 * 1024 * 1024, queueSize: 1 });
  }

How do I create a stream and write data to it?

1

1 Answer 1

1

below code works fine for me

const AWS = require('aws-sdk');
AWS.config.update({
        accessKeyId: process.env.AWS_KeyId,
        secretAccessKey: process.env.AWS_secret,
        // region:process.env.AWS_region  
});

const s3 = new AWS.S3({   signatureVersion: 'v4',  })
var multer = require('multer')
var multerS3 = require('multer-s3')
var photoBucket = new AWS.S3({
    params: {
        Bucket: 'carwhapps'
    }
})
// let source is like req.files.filename or test with static file like ./public/test.jpg
photoBucket.upload({
        ACL: 'public-read', 
        Body: fs.createReadStream(source), 
        Key: filename,
        ContentType: 'application/octet-stream' // force download if it's accessed as a top location
},(err, response)=>{
    console.log(err, response)

})
Sign up to request clarification or add additional context in comments.

2 Comments

Except I'm not reading from a file. I'm trying to write directly to the stream.
ok i already mention in express app with connect multiparty plugin you got file in req.files object and post file directly send to createReadStream() check me comment, provided that here you are not saving file in disk and http request already come to server as stream

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.