FormData POST请求引发网络错误

时间:2018-10-18 11:24:42

标签: node.js react-native fetch multipartform-data expo

我有一个react native应用程序,它允许用户将图像以及其他数据上传到服务器。

我正在使用NodeJS和ExpressJS作为后端框架。发布图像的路线:

--service-account=SERVICE_ACCOUNT

})

我正在使用axios进行ajax调用,而进行这些调用的函数如下所示:

router.post("/", checkAuth, upload.single("gallery_item_image"), function (req, res, next) {
Branch
    .findById({ _id: req.body.branch_id })
    .exec()
    .then((doc) => {
        if(!doc) {
            return res.status(404).json({
                message: "Invalid Branch ID",
            })
        }
        galleryItem = new GalleryItem({
            _id: mongoose.Types.ObjectId(),
            branch_id: req.body.branch_id,
            caption: req.body.caption,
            description: req.body.description,
            imageUrl: "https://someurl.com/" + req.file.filename,
            imageId: req.file.id,
        })
        return galleryItem.save()
    })
    .then((response) => {
            console.log(response);
            res.status(201).json({
                message: "Gallery item successfully added to the database",
                galleryItem: {
                    _id: response._id, 
                    branch_id: response.branch_id, 
                    caption: response.caption, 
                    description: response.description, 
                    date: response.date,
                    imageUrl: response.imageUrl,
                    imageId: response.imageId,
                    meta: {
                        type: "GET", 
                        url: "https://someurl.com/" + response._id,
                    }
                }
            })
        })
    .catch((error) => {
        console.log(error);
        res.status(500).json({
            error: error
        })
    })

但是,我总是得到“网络错误”,没有任何解释。

console output Application output

0 个答案:

没有答案