Trouble using FileSystem.FileSystemUploadType constants

Please provide the following:

  1. SDK Version: ~45.0.0
  2. Platforms(Android/iOS/web/all): Android/IOS
  3. Add the appropriate “Tag” based on what Expo library you have a question on.

So i’m building a marketplace mobile app using, expo that let users upload products to the marketplace. I’m having difficult times using the expo FileSystem.FileSystemUploadType to pick the image and send to the backend. here’s my front-end code

const handleSubmit = async (listing, { resetForm }) => {
    
    const data = new FormData();
    data.append("images", listing.images[0]);
    data.append("description", "Good product");

    console.log( listing.images[0])
   // it does console the file uri
   // file:///Users/zakisb/Library/Developer/CoreSimulator/Devices/83E12EA5-E8FA-4850-82C1-84021B25450D/data/Containers/Data/Application/6873BF40-26E4-4BD3-834D-F6772448C004/Library/Caches/ExponentExperienceData/%2540anonymous%252Flokazz_app2-5f4724db-b9d7-45aa-a8ca-ac5acf2f4780/ImagePicker/B72CF40C-EC27-430E-B1F8-B983C0ACF2FB.jpg
   
  // i tried this solution first and worked perfectly. but it does upload the image only and i want to send the formdata object
 const response = await FileSystem.uploadAsync(
      "http://192.168.43.8:5000/products/addProduct",
      listing.images[0],
      {
        fieldName: "images",
        uploadType: FileSystem.FileSystemUploadType.MULTIPART,
      }
    );

   // so i tried this but i get an error
    const response = await FileSystem.FileSystemUploadType.MULTIPART(
      "http://192.168.43.8:5000/products/addProduct",
      data
    );
    
  };

My backend works perfectly. i tried the api call using insomnia and postman the file gets uploaded successfully to the folder. but using expo methods i get nothing.

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) => {
    console.log(req.body);
    try {
      res.send(req.body);
    } catch (err) {
      res.send("Error " + err);
    }
  }
);
});


Please help !

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