Reputation: 119
I wanted to export the JSON data object to csv file and save it in download folder but I not sure where the file saved at or whether it has been saved or not. When i check the path it was written file:///data/user/0/host.exp.exponent/files/ExperienceData/UNVERIFIED-192.168.1.14-csvproject/test.csv
and when i check the FileSystem.writeAsStringAsync(path,csv,{ encoding: FileSystem.EncodingType.UTF8 })
it returns as
Promise { "_U": 0, "_V": 1, "_W": null, "_X": null, }
CSV=async()=>{
var data = this.state.results
var headers = 'Transaction ID, Title, Amount, Category, Note, Date'
var csv = `${headers}${data}`;
var path = FileSystem.documentDirectory+"test.csv";
var { status } = await MediaLibrary.requestPermissionsAsync();
console.log("status:", status)
if (status === "granted") {
FileSystem.writeAsStringAsync(path,csv,{ encoding: FileSystem.EncodingType.UTF8 })
var asset = await MediaLibrary.createAssetAsync(path)
await MediaLibrary.createAlbumAsync("Download", asset, false)
console.log(`wrote file ${path}`);
}
}
Upvotes: 0
Views: 395
Reputation: 171
You didn't use await and it return promise object instead of promise response
await FileSystem.writeAsStringAsync(path,csv,{ encoding: FileSystem.EncodingType.UTF8 })
and then when you are execute CSV fn
await CVS();
Upvotes: 1