小编Uza*_*air的帖子

multer - req.file 未定义。

我正在使用 Node、Express 和 Handlebars 创建一个应用程序,并使用 multer 上传图像。每次我提交表单时,req.file 都是未定义的。我花了一整天的时间进行故障排除,但无法弄清楚我做错了什么。

路由器文件:

const express = require('express');
const router = express.Router();
const multer = require('multer');
const mongoose = require('mongoose');
const path = require('path');
const methodOverride = require('method-override');


//Set Storage Engine
const storage = multer.diskStorage({
    destination: './public/uploads/images',
    filename: function (req, file, cb) {
        cb(null, file.fieldname + '-' + Date.now() + 
    path.extname(file.originalname));
    }
});

const upload = multer({
    storage: storage
}).single('featuredImage');

//Change Featured Image - POST
router.post('/saveImage/:id', (req, res) => {
    console.log(req.file);

    //removed the rest of …
Run Code Online (Sandbox Code Playgroud)

node.js express multer

6
推荐指数
1
解决办法
1万
查看次数

Shopify API Node/Express 无法读取未定义的属性(读取“Rest”)

刚刚开始使用 Shopify,并尝试获得订单。根据 Shopify API 文档,这是我的代码:

const Shopify = require('@shopify/shopify-api');

const client = new Shopify.Clients.Rest('my-store.myshopify.com', 
process.env.SHOPIFY_KEY);

module.exports.getShopifyOrderById = async (orderId) => {
return await client.get({ 
    path: `orders/${orderId}`,
  });
}
Run Code Online (Sandbox Code Playgroud)

当我执行此代码时,出现以下错误:

TypeError: Cannot read properties of undefined (reading 'Rest')

似乎无法弄清楚问题是什么。

node.js shopify express shopify-app shopify-api

5
推荐指数
1
解决办法
4859
查看次数

标签 统计

express ×2

node.js ×2

multer ×1

shopify ×1

shopify-api ×1

shopify-app ×1