[json响应给出错误[页面上的对象Object]

问题描述 投票:0回答:1

我正在尝试通过cloudinary multer在应用程序上上传图像和视频,但仅在图像(<1MB)响应带有[object Object]的页面时才适用于图像。我认为错误与响应有关,但我无法纠正。

发布路线

router.post("/", middleware.isloggedin, upload.array('images'), async function(req, res) {
    try {
        req.body.ca.images = [];
        for (const file of req.files) {
            req.body.ca.images.push({
                url: file.secure_url,
                public_id: file.public_id,
                format: file.format
            });

        }
        req.body.ca.author = {
            id: req.user._id,
            username: req.user.username
        }
        req.body.ca.created = new Date();

        const campground = await Campground.create(req.body.ca);

        res.redirect('/c/' + campground.id);
    } catch (err) {
        req.flash("error", err.message);
        res.redirect("back");
    }
});

<{ public_id: 'sample', version: '1312461204', width: 864, height: 564, format: 'jpg', created_at: '2017-08-10T09:55:32Z', resource_type: 'image', tags: [], bytes: 9597, type: 'upload', etag: 'd1ac0ee70a9a36b14887aca7f7211737', url: 'http://res.cloudinary.com/demo/image/upload/v1312461204/sample.jpg', secure_url: 'https://res.cloudinary.com/demo/image/upload/v1312461204/sample.jpg', signature: 'abcdefgc024acceb1c1baa8dca46717137fa5ae0c3', original_filename: 'sample' }

[[视频
的示例json响应

{ "public_id": "ygzxwxmflekucvqcrb8c", "version": 1427018743, "signature": "4618ba7c3461b6531cb9d2f16b06ce672af793b6", "width": 854, "height": 480, "format": "mp4", "resource_type": "video", "created_at": "2017-03-22T10:05:43Z", "tags": [ ], "bytes": 9094354, "type": "upload", "etag": "7e3977ca45a2c2a063e4f29fa3ecdfdd", "url": "http://res.cloudinary.com/demo/video/upload/v1427018743/ygzxwxmflekucvqcrb8c.mp4", "secure_url": "https://res.cloudinary.com/demo/video/upload/v1427018743/ygzxwxmflekucvqcrb8c.mp4", "audio": { "codec": "aac", "bit_rate": "246679", "frequency": 48000, "channels": 2, "channel_layout": "stereo" }, "video": { "pix_format": "yuv420p", "codec": "h264", "level": 31, "bit_rate": "5170819" }, "frame_rate": 29.97002997002997, "bit_rate": 5424041, "duration": 13.4134 }

我正在尝试通过cloudinary multer在应用程序上上传图像和视频,但仅在图像(<1MB)响应带有[object Object]的页面时才适用于图像。我认为...
javascript node.js express cloudinary
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.