Can't send an image using Image Picker on PC

I’m trying to send a picture to the server through the ImagePicker and the problem is that I managed to do it with the mobile version but for some reason it doesn’t work on Web.
Here is the code for front:

async function takeAndUploadPhotoAsync() {

  let result = await ImagePicker.launchImageLibraryAsync({
    allowsEditing: true,
    aspect: [4, 3],
  });

  if (result.cancelled) {
    return;
  }

  let localUri = result.uri;
  let filename = localUri.split('/').pop();

  let match = /\.(\w+)$/.exec(filename);
  let type = match ? `image/${match[1]}` : `image`;

  let formData = new FormData();
  formData.append('photo', { uri: localUri, name: filename, type });

  return await fetch("http://myIp:3000/uploadImage", {
    method: 'POST',
    body: formData,
  });

And here is the backend with mutler:

const multer = require('multer')
const storage = multer.diskStorage({
  destination: function(req, file, cb) {
    cb(null, "./data/")
  },
  filename: function(req, file, cb){
    cb(null, file.originalname)
  }
})
const upload = multer({storage: storage})

app.post("/uploadImage", upload.single("photo"),(req, res)=>{
  try {
    console.log(req.file)
    res.send("!")
  } catch (error) {
    res.status(500)
  }
})

What could be the problem?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.