简体   繁体   中英

expo- react native : there is way to see the content of the expo FileSystem and also delete content from there?

there is way to see the content of the FileSystem and also delete content from there?

i have data inside the expo FileSystem and i need:

  1. look inside FileSystem because i dont know how to find this file because i work with the expo client sdk with the qr code scan and i dont understand how can i find this file there.
  2. i want to know how to delete contents from the file system.
  3. how can i see the sqlite database as a real table?

this is my examle:

saveDbData = async () => {
    const { data, isLoaded } = this.state;
    for (let i = 0; i < data.length; i++) {
      const mediaData = data[i];
      const dbResult = await insertPlace(
        mediaData.artist,
        mediaData.image,
        mediaData.title,
        mediaData.url
      );
      console.log("SQL", `${FileSystem.documentDirectory}/SQLite/places.db`);
    }
    const fetchawesome = await fetchPlaces();
    console.log(fetchawesome)
  };

Since there are three questions from your part, I'll try to answer them one by one and provide a possible solution.

look inside FileSystem because i dont know how to find this file because i work with the expo client sdk with the qr code scan and i dont understand how can i find this file there.

You can access the file system using the FileSystem package from expo . Here's how you can do it. Import the package first.

import * as FileSystem from "expo-file-system";

Then you can find the URI of the file like this.

const { uri } = await FileSystem.getInfoAsync(
    `${FileSystem.documentDirectory}SQLite/${"yourDB.db"}`
  );

I want to know how to delete contents from the file system.

You can delete a file if you have access to its location or URI . This is how you can delete it. It returns a promise.

FileSystem.deleteAsync(fileUri)

how can I see the SQLite database as a real table?

This is a tricky part because since you're using your android phone to run the application via expo , you won't have direct access to your db . One thing you can do is to move the db to someplace else where you have access to and using the Sharing API from expo to save or send the db to yourself via email or any other way.

 import * as Sharing from "expo-sharing"; 

 let documenturi = `${FileSystem.documentDirectory}/yourDB.db`;
  await FileSystem.copyAsync({
    from: uri,
    to: documenturi,
  });
  Sharing.shareAsync(documenturi);

You can make this as a function which fire's on a Button press on you can even put this in useEffect or lifecycle methods to fire up when the screen loads.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM