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-type
if I am using fs.createReadStream()
?