I'm new to this, and I don't understand some things, but according to me this error is very strange, I'm using fastify-ts, multer and cloudinary, I want to tell result that the file path is the file to upload, but it doesn't tell me let
This is the code where I do the request:
fastify.post<{
Body: CreatePublicationBody;
Params: CreatePublicationParams;
}>(
"/create/:userId",
{
preHandler: upload,
},
async (request, reply) => {
const { description } = request?.body;
const { userId } = request.params;
const { path } = request.file;
const result = await v2.uploader.upload(path);
console.log(result);
const payload = {
userId: userId,
description: description,
image: result.secure_url,
};
await fastify.store.Publication.create(payload, (err, data) => {
if (err || !data) {
throw new Error("Error to create Publication");
} else {
return reply.status(200).send(data);
}
});
return "ok";
}
);
This is the error it gives me
And this is how I record it:
import fp from "fastify-plugin";
import multer from "fastify-multer";
import { File, FilesObject } from "fastify-multer/lib/interfaces";
import { v2 } from "cloudinary";
export default fp(async (fastify, opts) => {
fastify.decorate("someSupport", function () {
return "hugs";
});
void fastify.register(multer.contentParser);
v2.config({
cloud_name: process.env.CLOUD_NAME,
api_key: process.env.API_KEY,
api_secret: process.env.API_SECRET,
});
});
I believe your upload method expects a callback function as the second parameter, like this:
cloudinary.uploader.upload(path, function(error, result) {console.log(result, error)});
For reference: https://cloudinary.com/documentation/node_integration#quick_example_file_upload