面对使用React Native Fetch Blob和multer上传多个图像的问题

时间:2019-11-24 11:50:37

标签: react-native multer uploading react-native-fetch-blob

我正在使用RNFetchBlob和multer,我想将此数据结构发送到服务器。

1个人,具有多种工作经验,每种经验都有附件。

{
"email":"123qwert@abc.com",
"experience":[
    {
        "workTitle":"work1",
        "workDescription":"description1",
        "workUrl":"url1",
        "workAttachments":[
            {"name":"work1_image1_name","type":"work1_image1_type","data":"work1_image1_data"},
            {"name":"work1_image2_name","type":"work1_image2_type","data":"work1_image2_data"},
            {"name":"work1_image3_name","type":"work1_image3_type","data":"work1_image3_data"}
        ]
    },
    {
        "workTitle":"work2",
        "workDescription":"description2",
        "workUrl":"url2",
        "workAttachments":[
            {"name":"work2_image1_name","type":"work2_image1_type","data":"work2_image1_data"},
            {"name":"work2_image2_name","type":"work2_image2_type","data":"work2_image2_data"},
            {"name":"work2_image3_name","type":"work2_image3_type","data":"work2_image3_data"},
            {"name":"work2_image4_name","type":"work2_image4_type","data":"work2_image4_data"},
            {"name":"work2_image5_name","type":"work2_image5_type","data":"work2_image5_data"}
        ]
    },
    {
        "workTitle":"work3",
        "workDescription":"description3",
        "workUrl":"url3",
        "workAttachments":[
            {"name":"work3_image1_name","type":"work3_image1_type","data":"work3_image1_data"},
            {"name":"work3_image2_name","type":"work3_image2_type","data":"work3_image2_data"},
            {"name":"work3_image3_name","type":"work3_image3_type","data":"work3_image3_data"},
            {"name":"work3_image4_name","type":"work3_image4_type","data":"work3_image4_data"}
        ]
    }
]
}

我可以发送简单的文本字段,但是我在上传文件时遇到问题。

“ request.files”和“ req.body”始终为空。谁能指导我该怎么办?

在RNFetchRequest中发送的

数据是:

workData = {
            email: this.state.email,
            experience:this.state.WorkArray
        }

后端是:

app.post(path+'/SaveWorkExperiences',
        upload.any(),
        (req, res)=>{
            const errors = validationResult(req)
            if(!errors.isEmpty()) {
                return res.status(422).json({
                    errors: errors.array({onlyFirstError: true})
                })
            }
            AddWorkExperiences(req, res)
        })

break point applied at backend

0 个答案:

没有答案