In my NestJs application I have a file that is coming from a controller endpoint and it looks like this:
const file = {
fieldname: "file",
originalname: "filename.png",
encoding: "7bit",
mimetype: "image/jpeg",
buffer: BufferObject,
size: 2751
}
To parse the file and get data from it I use the following function:
public async fileOperation(file: File): Promise<OperationResult> {
const uploadedData = file.buffer.toString();
...
However, this code doesn't compile: TS2339: Property buffer does not exist on type File
.
What did you try and what were you expecting?
I'm trying to make an operation in an uploaded file without the use of any
.
The current code looks like this, it complies and its functional:
public async fileOperation(file: any): Promise<OperationResult> {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
const uploadedData = file.buffer.toString();
...
I expect to have a native type that can define the uploaded file.
Thanks to Jay McDoniel's comment I was able to solve this the following way: First npm install -D @types/multer
which was not installed in my application.
Then:
public async fileOperation(file: Express.Multer.File): Promise<OperationResult> {
const uploadedData = file.buffer.toString();