0

I want to pick an audio file in Flutter. I use file_picker package to pick an audio file. After picking it, I want to upload the file to AWS Storage, but the file in the path of the picked file does not exist. I check it by the following code snippet:

FilePickerResult? pickedAudioResult = await FilePicker.platform
          .pickFiles(type: FileType.any, withData: true);

if (pickedAudioResult == null) return;
PlatformFile pickedFile = pickedAudio.files.single;

print('Does file exist? ${await File(pickedFile.path!).exists()}');
print('File name: ${pickedFile.name}');
print('File extension: ${pickedFile.extension}');
print('File path: ${pickedFile.path}');
print('File size: ${pickedFile.size}');

And the log output is:

Does file exist? false
File name: best ringtones - most romantic 2018.mp3
File extension: mp3
File path: /storage/emulated/0/Android/data/com.salamgram.salamgram/files/Ringtones/best ringtones - most romantic 2018.mp3
File size: 0

I am confused by its strange behavior as it gives some info but doesn't give other. So how can I get the chosen file as a File object?

sm_sayedi
  • 326
  • 2
  • 17
  • how do you want to upload that file? what API are you using? post an url to that package – pskink Dec 23 '22 at 19:20
  • @pskink I use **Amplify** package to upload the audio file to **AWS S3 Storage**. It takes a **File** object as a parameter. So my whole point is to get the valid **File** object from the picked file. – sm_sayedi Dec 23 '22 at 19:27
  • this one: https://pub.dev/documentation/amplify_core/latest/amplify_core/StoragePluginInterface/uploadFile.html? – pskink Dec 23 '22 at 19:39
  • @pskink I think you didn't get my point. I want to get a valid file from file_picker package. So then I can upload it. – sm_sayedi Dec 23 '22 at 19:41

0 Answers0