如何将图像从react native上载到express后端?

如何将图像从react native上载到express后端?,express,react-native,multer,expo,Express,React Native,Multer,Expo,我按照这个示例将图像上载到后端 我在RN应用程序中使用的代码是: let formData = new FormData(); formData.append('name',this.state.name); formData.append('description',this.state.description); formData.append('price',this.state.price); formData.append('oprice',this.state.

我按照这个示例将图像上载到后端

我在RN应用程序中使用的代码是:

  let formData = new FormData();

  formData.append('name',this.state.name);
  formData.append('description',this.state.description);
  formData.append('price',this.state.price);
  formData.append('oprice',this.state.oprice);

  let fileArr = (this.state.image).split('.');
  let type = fileArr[fileArr.length -1]
  let uri = this.state.image


  formData.append('photo',{uri, name: `${this.state.name}.${type}`, type: `image/${type}`});
  console.log(formData);

  AsyncStorage.getItem('jwt', (err, token) => {

  fetch('http://192.168.1.83:8000/ShopRouter/deal', {
    method: 'POST',
    headers: {
      Accept: 'application/json',
      Authorization: token,
      'Content-type': false
    },
    body: formData
  })
我用于express后端的代码是:

 app.post('/ShopRouter/deal', passport.authenticate('jwt2', {session:false}), function(req,res) {
    upload(req, res, function(err) {
        if (err) {
            console.log(err);
        }

        console.log(req.file);
        console.log(req.files);
        console.log(req.photo);


        console.log(req.body.name);
        console.log(req.body.description);
我的Multer配置为:

var storage = multer.diskStorage({
  destination: function (req, file, cb, err){
    console.log(file)
    if (err){
      console.log(err)
     }
   cb(null, './uploads/')
  },
 filename: function (req, file, cb) {
   console.log(file)
   cb(null, file.originalname + '-' +Date.now())
  }
 });
  var upload = multer({ storage: storage }).single('photo');
打印行console.log(文件)

{fieldname:'照片', 原名:“一个空瓶子.jpg”, 编码:“7bit”, mimetype:'image/jpeg'}

一,;我不知道为什么后端接收到这个没有uri的图像,没有得到任何保存在上传文件夹


req.file返回时没有定义。

我只是通过将图像上传到s3来解决这个问题