What is the best way to create a text file with a given string to a phones local storage?

Please provide the following:

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

The following code creates a file test.txt under Internal Storage/Pictures/TestFolder/
Is it possible to make it save to the downloads folder? How should this be done properly in Android 11 given the new restrictions?

import * as MediaLibrary from 'expo-media-library';
import * as FileSystem from 'expo-file-system';

var data = "Test Data String"
const res = await MediaLibrary.requestPermissionsAsync();
if (res.granted) {
              var fileUri = FileSystem.documentDirectory + "test.txt";
              await FileSystem.writeAsStringAsync(fileUri, data, { encoding: FileSystem.EncodingType.UTF8 });
              const asset = await MediaLibrary.createAssetAsync(fileUri)
              await MediaLibrary.createAlbumAsync("TestFolder", asset, false)
} else {
             console.log("permission not granted")

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