0

I was trying to convert a code that was written using fs.readFile() to a code uses fs.createReadStream() like below:

const filePath = "/home/a/bars/img1.png";

const uploadParams: { Bucket: string; Key: string; Body: string | ReadStream; ContentType: any; ACL: string } = {
  Bucket: bucketName,
  Key: '',
  Body: '',
  ContentType: null,
  ACL: 'public-read',
};

const fileStream = fs.createReadStream(filePath);
fileStream.on('error', function (err) {
  console.log('File Error', err);
});
uploadParams.Body = fileStream;
uploadParams.Key = path.basename(filePath);
uploadParams.ContentType = fileStream.mimetype;
uploadParams.ACL = 'public-read';

But at this line fileStream.mimetype; I ended up getting the following error:

Property 'mimetype' does not exist on type 'ReadStream'.ts(2339)

I searched through the internet but couldn't find a solution. How can I find the Content-typeif I am using fs.createReadStream()?

best_of_man
  • 643
  • 2
  • 15
  • There is no `mimetype` property on `ReadStream` type. Why not just assign `application/octet-stream` to `ContentType`? – Lin Du Jan 29 '23 at 05:16
  • @LinDu: I am completely new to this and don't know what other options I have to use. I only wanted to convert that code snippet and ended up with the above error. Could you explain more about `application/octet-stream`? How it can find out my selected file is an image or video or a pdf file for example? – best_of_man Jan 29 '23 at 06:14

0 Answers0