anacronw / multer-s3

multer storage engine for amazon s3
MIT License
662 stars 193 forks source link

Property 'location' does not exist on type 'File' #214

Open NikhilMandaliya opened 7 months ago

NikhilMandaliya commented 7 months ago
public create = async (req: Request, res: Response) => {
  req.body.profileImage = req.file?.location;
  req.body.user = req.tokenData.user;
  const responseData = await this.userRepository.createUser(req.body as CreateUserInterface);
  return generalResponse(req, res, responseData, successMessage.USER_CREATE_SUCCESS, false, responseFlag.SUCCESS);
};

This code block, throws this TS error

TSError: ⨯ Unable to compile TypeScript:
src/controllers/user/user.controller.ts:24:39 - error TS2339: Property 'location' does not exist on type 'File'.

24     req.body.profileImage = req.file?.location;

Log of req.file if working fine

req.file:  {
  fieldname: 'profileImage',
  originalname: 'profile.jpeg',
  encoding: '7bit',
  mimetype: 'image/jpeg',
  size: 6182,
  bucket: 'aws-bucket-name',
  key: '1711716164482-profile.jpeg',
  acl: 'private',
  contentType: 'application/octet-stream',
  contentDisposition: null,
  contentEncoding: null,
  storageClass: 'STANDARD',
  serverSideEncryption: null,
  metadata: { fieldName: 'profileImage' },
  location: 'http://localhost:4566/aws-bucket-name/1711716164482-profile.jpeg',
  etag: '"806170f0b2a191c8c967372af939cc6d"',
  versionId: undefined
}
NikhilMandaliya commented 7 months ago
const file = req.file as Express.MulterS3.File;
const profileImage = file?.key;

This works But type of req.file if Express.Request.file?: Express.Multer.File | undefined Shouldn't it be Express.Request.file?: Express.MulterS3.File | undefined??

C-Collamar commented 5 months ago

I have stumbled upon the same issue using multer@1.4.5-lts.1, which is the latest at the time of this writing.

image