File Picker Plugin Causes Increasing Storage Usage on Android
Hi, I’m using your file picker plugin in my Unity Android app, and I noticed that each time I select a file, the app's storage usage increases. Even after closing the app, the extra storage is not freed. I suspect that the plugin might be copying files into the app’s private storage or cache directory and not cleaning them up. Could you clarify how the plugin handles selected files and if there’s a way to prevent unnecessary storage accumulation? Here are my details: Unity Version: [2022.3.17f1c1] Plugin Version: [v1.6.6] Android Version: [13] Thanks for your help!
Hi,
Plugin isn't supposed to copy files on its own. May I ask which FileBrowserHelpers functions you're using?
I think I am copying the data to the private directory in this part of the code because I was concerned that Android 10+ might not support reading the file directly. How can I improve this?
void OnFilesSelected(string[] filePaths, System.Action<bool, string> actionResul)
{
// Print paths of the selected files
for (int i = 0; i < filePaths.Length; i++)
Debug.Log(filePaths[i]);
// Get the file path of the first selected file
string filePath = filePaths[0];
// byte[] bytes = FileBrowserHelpers.ReadBytesFromFile(filePath);
// Or, copy the first file to persistentDataPath
string destinationPath = Path.Combine(Application.persistentDataPath, FileBrowserHelpers.GetFilename(filePath));
FileBrowserHelpers.CopyFile(filePath, destinationPath);
actionResul(true, destinationPath);
// Read the bytes of the first file via FileBrowserHelpers
// Contrary to File.ReadAllBytes, this function works on Android 10+, as well
//byte[] bytes = FileBrowserHelpers.ReadBytesFromFile(filePath);
// selectimagr(filePath);
// Or, copy the first file to persistentDataPath
// string destinationPath = Path.Combine(Application.persistentDataPath, FileBrowserHelpers.GetFilename(filePath));
// FileBrowserHelpers.CopyFile(filePath, destinationPath);
}
你好
插件不应该自己复制文件。请问您使用的是哪些 FileBrowserHelpers 函数吗?
I was concerned that Android 10+ might not support reading the file directly.
You're right about that. If you're only interested in reading the file's bytes, then I'd recommend uncommenting the byte[] bytes = FileBrowserHelpers.ReadBytesFromFile(filePath); line and not copying the file manually. An alternative solution would be to have a constant string destinationPath and overwrite that same file with each FileBrowserHelpers.CopyFile call.
Thank you for your reply. Would there be a better solution, for example, manually deleting the temporary file once it has served its purpose?
That's also a solution. After you no longer need the file, you can delete it in your code.