Trouble using expo file upload

So i’ve been trying to wrap my head around uploading an image to backend node.js server, but i’m having trouble understanding the doc and the process. Note that i’ve already done this in a web app before using react in the front and multer in the backend. done it multiple times without trouble. I’ve found the expo-file-system package which is helpful. FileSystem - Expo Documentation globalfintechleaders

i’m having trouble understanding the FileSystem.uploadAsync method. Here’s all code listed down below. a normal axios api call to upload the image would look like this

const data = new FormData();
data.append("images", listing.images[0]);

await axios({
      method: "post",
      url: "http://localhost:5000/products/addProduct",
      data: data,
      headers: { "Content-Type": "multipart/form-data" },
    })
      .then((response) => {
        console.log(response);
      })
      .catch((error) => {
        //
      });

the backend

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


router.post(
  "/products/addProduct",
  upload.single("images"),
  async (req, res) => {
    try {
      res.send("ok");
    } catch (err) {
      res.send("Error " + err);
    }
  }
);

Also, i tested the backend using an api client (insomnia) it works without a problem !

So please how can i use the FileSytem.uploadAsync method to upload my images to the backend !!!

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