flutter – no such file or directory when i try to upload file on ios

0
189


i try to pick audio file on ios device, and when upload file with the DIO i got no such file or director. I pick file with then file_picker. After that i tried to copy file (if current device is ios) to getApplicationDocumentsDirectory, but got this message on copy proccess

`

 void selectAudio() async {
    final FilePickerResult? result = await FilePicker.platform.pickFiles(
      type: FileType.audio,
      allowMultiple: true,
    );
    if (result == null) return;
    if (fileList.length + result.files.length > 6) {
      Get.showErrorMessage(
        'txt_oops'.tr,
        'txt_max_amount_of_selected_files'.tr,
      );
      return;
    }
    for (PlatformFile file in result.files) {
      fileList.add(
        FileModel(null)..localfile = file.path,
      );
    }
  }

  Future<void> uploadFile(FileModel file, String mimeType) async {
    File localFile = File(file.localfile!);

    if (Platform.isIOS) {
      String documentPath = (await getApplicationDocumentsDirectory()).path;

      localFile = await localFile.copy(
        '$documentPath/${basename(localFile.path)}',
      );
    }

………

Future<FileModel?> uploadFile({
    required int profileId,
    required File file,
    void Function(int current, int total, int percent)? onSendProgress,
  }) {
    return uploadFileToServer(
      url: "profile/$profileId/file/",
      onSendProgress: onSendProgress == null
          ? null
          : (int current, int total) {
              int percent = (current / total * 100).toInt();
              onSendProgress(current, total, percent);
            },
      formData: dio.FormData.fromMap({
        "file": dio.MultipartFile.fromFileSync(
          file.path,
          filename: basename(file.path),
        ),
      }),
    );
  }
    

`