How Can I Solve FileSystemException: Cannot retrieve length of file

Viewed 25
final ImagePicker _picker = ImagePicker();
  RxList<File> files = RxList([]);

  void pickImage([int? index]) async {
    final pickedFile = await _picker.pickImage(
      source: ImageSource.gallery,
      maxWidth: 1500,
      maxHeight: 1500,
      imageQuality: 90,
    );

    if (pickedFile != null) {
      if (index == null) {
        files.add(File(pickedFile.path));
        files.forEach((e) {
          filePath = e.toString().obs;
        });
      } else {
        files[index] = File(pickedFile.path);
        files.forEach((e) {
          filePath = e.toString().obs;
        });
      }
    }
  }

  //Function Upload Documentation ====================================
  RxString filePath = ''.obs;
  //ChangeProfilePicture
  Future uploadDocum(int? id) async {
    try {
      Indicator.overlay();

      // create file data
      String fileName = '${DateTime.now().millisecondsSinceEpoch}.jpg';

      // Send File Image with multipart
      MultipartFile file =
          await MultipartFile.fromFile(filePath.value, filename: fileName);

      Map<String, dynamic> map = {
        'images': [file],
        '_method': "PUT",
      };

      ResHandler res = await api.updatePhoto(map, id);

      if (res.status) {
        // alert info
        toast.info('Succes To Upload');

        //Kembali Ke Halaman Sebelumnya
        Get.back();
        return Indicator.close();
      }
      Indicator.close();
      Fn.toast('Failed To Upload');
    } catch (e, s) {
      Indicator.close();
      ErrorHandler.check(e, s);
    }
  }

Im trying to upload multiple images to the server using dio, i can upload one picture at a time but i need to upload multiple files of images all at the same time here is my function: The First function is to pick an image and the file path it will be store in the list of files, an then i set list of file to filepath varibale using for each

0 Answers
Related