Within my NestJs application, I have a file being returned from a controller endpoint with the following structure:
const file = {
fieldname: "file",
originalname: "filename.png",
encoding: "7bit",
mimetype: "image/jpeg",
buffer: BufferObject,
size: 2751
}
To extract data from this file, I utilize the function below:
public async fileOperation(file: File): Promise<OperationResult> {
const uploadedData = file.buffer.toString();
...
Unfortunately, this code is generating an error during compilation:
TS2339: Property buffer does not exist on type File
.
What steps have you taken and what were your expectations?
My aim is to perform operations on an uploaded file without using any
.
The current functional version of the code includes the use of any
:
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 am hoping to find a solution with a specific type definition for the uploaded file.