Uploading an image using expo file system

Viewed 68

So i'm having a lot of troubles trying to send an image to backend server ( node.js) with expo file system. I have been trying this since weeks read thousands of forums yet i can't make it work. please help me out My expo front-end code

const handleSubmit = async (listing, { resetForm }) => {
try {
      const response = await FileSystem.uploadAsync(
        "http://localhost:5000/products/addProduct",
        // this gives the file path of the image in the expo device file system
        listing.images[0]
      );
      console.log(response);
    } catch (e) {
      console.error(e);
    }

my backend

/// multer config
const storage = multer.diskStorage({
  destination: function (req, file, cb) {
    cb(null, "./images");
  },
  filename: function (req, file, cb) {
    cb(null, Date.now() + file.originalname);
  },
});

// backend api call 
router.post("/products/addProduct", upload.single("images"), async (req, res) => {
    
    try {
      // to see if the api call worked
      // i receive the ok response but the file doesn't get uploaded 
      res.send("ok");
    } catch (err) {
      res.send("Error " + err);
    }
  }
);

}

Please note that the backend is working fine. when i try to upload an image using insomnia the file gets uploaded without a problem in my image folder. meaning the problem reside in my front-end code ! Please let me know if i should provide you with additional code

0 Answers
Related