1

I'm using the Amplify Framework to download a file from S3 and have been following AWS's documentation. I've successfully downloaded the file, but I have no idea where it is saved, or how to access it. The documentation doesn't say, and I'm a bit confused as it doesn't appear in the project files. Can someone explain it to me, or point me in the right direction? What are the next steps to access the files content? In this case it's a plain text file, but once I've read that file, I intend to move on to reading JSON files.

Here's the code I'm using to download the file.

Amplify.Storage.downloadFile(
    "myfile.txt",
    new File(getApplicationContext().getFilesDir() + "/download.txt"),
    result -> Log.i("MyAmplifyApp", "Successfully downloaded: " + result.getFile().getName()),
    error -> Log.e("MyAmplifyApp",  "Download Failure", error)
);
Jameson
  • 6,400
  • 6
  • 32
  • 53
Brian16446
  • 149
  • 1
  • 13
  • can you locate this file on your computer? where is it? – David Thery Sep 11 '20 at 14:36
  • no, but when I call getAbsolutePath() on the file object, I can see the filepath is: /data/user/0/com.example.amplifyapp/files/download.txt - However, I can't find that location on my pc – Brian16446 Sep 11 '20 at 15:00
  • Does [this answer](https://stackoverflow.com/questions/61169547/cant-find-the-saved-data-to-text-file-in-internal-storage-how-to-save-file-in-i) help? – char Sep 12 '20 at 15:17
  • Yes it does, amazing thank you. Now I know that the file is downloading, how do I read it from there? – Brian16446 Sep 16 '20 at 14:18

1 Answers1

0

Based on the comments, I want to be sure that one key point is clear. The Amplify library will download the file into the storage on your Android device. It will not save the file on your computer/PC.

If you want to view the downloaded file on your PC, you need to pull it from the Android phone using adb pull. Until you do that, the content will only ever be on your Android phone.

In your case, you have chosen to download the file to into an app-specific file storage area on your Android device:

/data/user/0/com.example.amplifyapp/files/download.txt

From your Android application, you could continue to reference the File handle, as you do above:

String appSpecificFilesDir =
    getApplicationContext().getFilesDir();
String textFilePath =
    appSpecificFilesDir + "/download.txt";
File file = new File(textFilePath);
Jameson
  • 6,400
  • 6
  • 32
  • 53