简体   繁体   English

我不知道为什么它给我这个错误与 fastify-ts、multer 和 cloudinary

[英]I don't know why it gives me this error with fastify-ts, multer and cloudinary

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我是新手,有些东西我不明白,但在我看来这个错误很奇怪,我正在使用fastify-ts,multer和cloudinary,我想告诉结果文件路径是文件上传,但它并没有告诉我让

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这是它给我的错误

enter image description here在此处输入图像描述

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<\/code> method expects a callback function as the second parameter, like this:我相信您的upload<\/code>方法需要一个回调函数作为第二个参数,如下所示:

cloudinary.uploader.upload(path, function(error, result) {console.log(result, error)});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM