Search Unity

Simple File Browser [Open Source]

Discussion in 'Assets and Asset Store' started by yasirkula, Nov 19, 2016.

  1. blevok

    blevok

    Joined:
    Feb 16, 2017
    Posts:
    75
    Amazing... it actually works! I almost can't believe it. It worked perfectly in another new test project, so i then did what you said to add it to my real project, and it worked just as well.
    No native dialogs, no android BS of any flavor, just drives, right there, ready to click. I opened files from both drives, and everything seems to work, i haven't found any problems at all yet.
    It's simple and intuitive, and it looks the same on every OS version i've tested.

    Here's a screenshot of it working in the old and modified version of the file browser...



    You are amazing, your assets are amazing, and your support is amazing.
    It's just a shame that your assets are so expensive... NOT! Hahaha i love that!

    I don't know how i can properly thank you. Oh wait, yes i do... I just bought you a coffee, or ten, depending on where you buy your coffee. Or you could blow it all on tacos, because tacos are pretty great too.

    Thanks so much.
     

    Attached Files:

    yasirkula likes this.
  2. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Thank you for your support! I'll be updating the asset on Asset Store with this change, as well.
     
    blevok likes this.
  3. darkhelmet2005

    darkhelmet2005

    Joined:
    May 26, 2014
    Posts:
    9
    Hello,

    First off, amazing work on this asset. Your support appears to be great as well just looking through this forum. Thank you for being amazing.

    I am running into an authorization error when I try to save to external storage. The error from Android Studio is

    2021-05-15 16:18:21.572 22409-22490/? E/Unity: UnauthorizedAccessException: Access to the path "/storage/0000-0000/tempstring.csv" is denied.
    My code is below. A user selects a path, names their file, and then can choose to save the file to that path or cancel out of the prompt. Is the error when trying to save to an external drive expected? This code works fine for internal android storage, as well as at runtime in the Unity Editor (on Windows). I am currently testing on Android 8.0. Please let me know what other information i can provide.

    Code (CSharp):
    1. public void FolderBrowsePush () {
    2.        SimpleFileBrowser.FileBrowser.ShowLoadDialog( ( paths ) => { folderBrowsePath = paths[0]; PromptWriter(); PlayerPrefs.SetString("InitialLoadPath",paths[0]); }, () => { }, FileBrowser.PickMode.Folders, false, folderBrowsePath, null, "Save to", "Select");
    3. }
    4.  
    5. private string FilePathCreater () {
    6.         string filename = userspecifiedfilename.text;
    7.         if (folderBrowsePath != "") {
    8.             return folderBrowsePath + "/" + filename + "_" + DateTime.Now.ToString("yyyy-MM-dd_hh.mm.ss") + ".csv";
    9.         }
    10. }
    11.  
    12. public void FileWriter() {
    13.         string filepath = FilePathCreater();
    14.         SimpleFileBrowser.FileBrowserHelpers.WriteTextToFile( filepath, stringtoprint );
    15. }
     
    Last edited: May 17, 2021
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I'm assuming that changing DateTime.Now.ToString to "tempstring" has no effect? Can you check if your SD card is in read-only mode?

    For Android 11 compatibility, I'd recommend you to modify FilePathCreater as follows: return
    FileBrowserHelpers.CreateFileInDirectory(folderBrowsePath, filename + "_" + DateTime.Now.ToString("yyyy-MM-dd_hh.mm.ss") + ".csv");
     
  5. darkhelmet2005

    darkhelmet2005

    Joined:
    May 26, 2014
    Posts:
    9
    Thanks for the quick response.

    Sorry for the disconnect between DateTime.Now.ToString and tempstring. I was trying a lot of different things at the time and failed to provide a recent error message. To answer your question directly, changing the file name does not make it work.

    Your suggestion to change the FilePathCreater routine did help the problem I was seeing with Android 11 phones, though. Thank you for that. I actually changed my FileWriter routine to the code below and am no longer using the FilePathCreater routine at all. Hopefully you don't see any issue with it, it seems to work fine.
    Code (CSharp):
    1.     private void FileWriter() {
    2.         string stringtoprint = StringWriter();  // information for CSV file
    3.         string filename = userspecifiedfilename.text;
    4.         SimpleFileBrowser.FileBrowserHelpers.WriteTextToFile( FileBrowserHelpers.CreateFileInDirectory(folderBrowsePath, filename + "_" + DateTime.Now.ToString("yyyy-MM-dd_hh.mm.ss") + ".csv"), stringtoprint );
    5.     }
    In regards to the SD card, it is not set to read only. I am able to transfer files to and from the card without any issues. I am hitting the same error on an older phone of mine as well. Is there any way to show internal drives only?
     
  6. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    To exclude external drives, you can change this for-loop as follows:
    for( int i = 0; i < drives.Length && !defaultPathInitialized; i++ )
     
  7. darkhelmet2005

    darkhelmet2005

    Joined:
    May 26, 2014
    Posts:
    9
    I'll keep trying to figure out what's going on with my external drives, but for now this will work great! Thank you so much!
     
    yasirkula likes this.
  8. darkhelmet2005

    darkhelmet2005

    Joined:
    May 26, 2014
    Posts:
    9
    Hello again,

    Just curious as to the reason you included this line which clears the file name when selecting a different path to save to. I replaced it with { } as I would like to keep the initial file name I set in the ShowSaveDialog() routine. Just hoping to better understand your thought process so I can better understand what I am affecting. Thanks again!
     
  9. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    darkhelmet2005 likes this.
  10. darkhelmet2005

    darkhelmet2005

    Joined:
    May 26, 2014
    Posts:
    9
    What strange timing. Your suggestions appears to work great, though!
     
  11. unity_fcR95LTMy8E1LA

    unity_fcR95LTMy8E1LA

    Joined:
    Apr 1, 2020
    Posts:
    5
    Hello!! I have an issue.. I made my app for iPad. The file browser works fine but, as we know, we can't access to files that are not appfiles (persistent Data, tmp, etc..). So I thought maybe I can put the files I need in one of this accesible/permitted folders. The thing is this, these folders are not visible for the user outside the app. Does anyone know how to put these files visible by code(c#) (or some other way)? Thank you!! If anyone has another solution, of course I'm all ears
     
  12. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Where will these files be visible to? I mean using which external app/method do you want to see those files?
     
  13. unity_fcR95LTMy8E1LA

    unity_fcR95LTMy8E1LA

    Joined:
    Apr 1, 2020
    Posts:
    5
    From the file folder, I mean the iPad's own file explorer (This way I can move files that I need to open with my iOS app, other way I don't know how to see it)
     
  14. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    The closest thing I have to that is NativeFilePicker. With SimpleFileBrowser, I don't know if there is a way to save files to the folders shown in file explorer. I didn't conduct extensive tests on iOS.
     
  15. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You can call FileBrowser.SetFilters and then, optionally, FileBrowser.SetDefaultFilter. You can find a list of all methods on GitHub page or the included README file.
     
    sadren likes this.
  16. sadren

    sadren

    Joined:
    Jun 12, 2017
    Posts:
    1
    thnx
     
  17. JPUlisses

    JPUlisses

    Joined:
    Apr 23, 2014
    Posts:
    6
    Been using for a while and it works perfectly for all cases.

    Except in WebGL where it still works but it is server only and not the client.

    I know it is not supported, but any plans to include a WEBGL client solution to read files from the user that could be potentially used in the application or downloaded into the server?
     
  18. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I've investigated WebGL support in the past and found the required architecture much different from SimpleFileBrowser's current design.

    For security reasons, most browsers don't allow displaying dialogs out of nowhere, there has to be a user interaction. A common user interaction is mouse click; however you can't tell the browser to display a dialog on mouse up event. It didn't work on some of the major browsers in my tests. You have to add a hidden HTML button on mouse down and then the browser will allow displaying dialogs on mouse up because you'll technically be clicking that HTML button and it is a valid user interaction. This means we have to detect mouse down on the UI button that triggers the dialog, add an HTML button to the web page, connect an HTML dialog to that button and pass the result of that dialog to Unity.

    Save dialog implementation was even worse. You need to pass the whole file as a byte[] array to WebGL on mouse down event. You can check out this repository's WebGL implementation to see what I'm talking about: https://github.com/gkngkc/UnityStandaloneFileBrowser

    I'd recommend you to use a dedicated WebGL plugin like one of these (haven't used any of them myself):
     
    JPUlisses likes this.
  19. JPUlisses

    JPUlisses

    Joined:
    Apr 23, 2014
    Posts:
    6
    Thank you for your reply, in fact I already did what you said and got 3 results in byte[] using gkngkc solution. It also allows multiple files and to filter by a type of format such as .pdf.
    It is working.

    I think the trick from that solution is from javascript it calls a operative system browser base thing which seems safe to do in browsers. This solution startrs on webgl button, which then calls a javascript that does all this, and returns all to unity using the message method.

    Now I am planning to use a PhP script to grab those byte[] and save the .pdf files. This PhP will be called when those byte[] are returned to make sure it all runs when it is supposed to.

    I wonder if you could create this javascript for this task and put in simplefilebrowser, so that simpefilebrowser is more complete, as despite UnityStandaloneFileBrowser is working for me now, I read many drawbacks and issues and dependency on mono. Although from my windows and webgl testing it all works. Unity LTS 2020.3.3f1

    Offtopic: your other tool, ingamedebugconsole is a life saver for webgl!
     
    yasirkula likes this.
  20. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I really can't promise anything about WebGL but I appreciate your interest in this topic.
     
    JPUlisses likes this.
  21. Strygel

    Strygel

    Joined:
    Jul 11, 2021
    Posts:
    1
    Hello Sir, how can I fix this? There seems to have a 2 event systems happening to my scene, since I am using the script through a button. I used your example code in your Github page and then place it to the GameObject and to the button. Sorry for being a newbie.
     

    Attached Files:

    Last edited: Jul 21, 2021
  22. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    If all your scenes already have EventSystem, you can delete SimpleFileBrowserCanvas prefab's EventSystem child object.
     
  23. SilentAndroid

    SilentAndroid

    Joined:
    Sep 18, 2017
    Posts:
    3
    Hello! I make an application on Unity and then I make a build for android. In Android OS 10 and 11, access to external storage is limited.

    I am looking for code to copy a file from external storage to internal storage.

    I tried your Unity Simple File Browser. It works great.

    But for my purposes, it would be better if the user selects a file through the standard native gallery. And then I would work with a internal copy of this file inside the application.

    So I have some questions:

    1) Does Unity Simple File Browser only work in the non-native interface?

    2) Does Unity Simple File Browser use the android requestLegacyExternalStorage=true flag or not?

    3) Does Unity Simple File Browser works equally well under 10 and 11 versions of android?

    4) Does Unity Native File Picker Plugin work with native gallery?

    5) Does the Unity Native File Picker Plugin use the android requestLegacyExternalStorage=true flag or not?

    6) Can Unity Native File Picker Plugin work only up to android version 10? Can this plugin work under android 11?

    7) Is it possible somehow, using your code, to achieve the result I need? I need to select a file through the native gallery and then copy it to the internal storage in the Android OS 10 and 11 WITHOUT this flag.

    Thank you very much for your support! And sorry for the many questions. :)
     
  24. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    1) That's correct
    2) It does (see FAQ). There is nothing wrong with using that attribute, at least while publishing to Google Play. Don't know about the other stores
    3) requestLegacyExternalStorage attribute allows the file browser the act the same on all OS versions up to 10 (inclusive). After Android 11+, Storage Access Framework is used and the user experience changes a bit. Users must click the "Browse..." button in the user interface to pick a folder using a native dialog and then they can browse that folder's contents using the file browser's UI (inside Unity)
    4) None of my plugins depend on each other and they shouldn't cause any compatibility issues when imported to the same project
    5) It doesn't
    6) It should work on all Android versions and the user experience should be the same
    7) NativeGallery will return a copy of the selected image/video to you. You can copy it to persistentDataPath using File.Copy (i.e. no other plugin is needed). If you want to select the destination folder using SimpleFileBrowser, you can
     
  25. TheRebirth2393390183

    TheRebirth2393390183

    Joined:
    Jun 5, 2017
    Posts:
    8
    I couldn't be any happier to know that a free file browser asset actually exists! Thanks for giving this asset for free. I really wanted to test it out and rate this asset 5 star after I made sure it works, but...
    It crashes Unity editor immediately after I try to expand the prefab "SimpleFileBrowserCanvas" which is under Resource folder, when using 2021.2.0a8 or 2020.3.14f1c1. I'll try it on older versions of Unity but meanwhile maybe you can take a look at this issue?

    Edit: Just confirmed it doesn't crash after I deleted Symlink asset. Really wish I can keep both! I wonder what exactly could've caused this crash...
     

    Attached Files:

  26. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    If you import the asset to a project without Symlink and then copy it from that project to the project with Symlink, does it work? And can you send the following files via private message so that I can understand which functions are executed at the stack trace lines:
    • DetermineIfGameObjectIsInSymLink.cs
    • SymLinksOnHierarchyItemGUI.cs
     
  27. SilentAndroid

    SilentAndroid

    Joined:
    Sep 18, 2017
    Posts:
    3
    Thank you very much for the detailed response and great support! UnityNativeGallery looks like exactly what I need. :)
    I tried UnityNativeGallery. Works fine on Android 8 and Android 10 (my real devices). But I have no way to test the application on a real device with Android 11. Can you clarify - does UnityNativeGallery work fine on android 11 as well?
    Does UnityNativeGallery take into account the new way of working with storage in android 11?
    Thanks!
     
  28. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I didn't test the plugin on Android 11 myself so I can't personally assure you that it works. Though, there was a review stating that it worked fine on Android 11:

    Untitled.png

    NativeGallery doesn't do anything special while picking media on Android 11. It uses
    ACTION_PICK
    ,
    ACTION_GET_CONTENT
    and
    ACTION_OPEN_DOCUMENT
    intents which are supposed to work on all Android versions.
     
    SilentAndroid likes this.
  29. SilentAndroid

    SilentAndroid

    Joined:
    Sep 18, 2017
    Posts:
    3
    Thanks, I'm glad to hear that! Thank you for providing your work for free! This is amazing!
     
    yasirkula likes this.
  30. soundmartell

    soundmartell

    Joined:
    Oct 31, 2013
    Posts:
    16
    Hello, I installed the File Browser in Unity 2021.1.6f1 personal.
    I dragged the "SimpleFileBrowserCanvas" from resources folder to the Hierarchy.
    When I run the project I can see the Browser but not any files or folders are showed.
    I am not getting any errors in the console.
    The Cancel button close the Browser, and of course, as there is not any file select the file name become red as a Wrong filename Color.
    Am I missing something else to make it work?
    Note I am running in the Unity Editor but my Building setting is set to Android.
    Regards.
     
  31. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  32. soundmartell

    soundmartell

    Joined:
    Oct 31, 2013
    Posts:
    16
    @yasirkula Thank you. It is working perfect in Unity editor and in Note 10 plus.
    Is it possible to force to only one folder? I mean, I don't want the Browser allow the user to go to any other folder directory than the one in the initialPath.
    Thanks
     
  33. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    How will this behave on Android 11+, when Storage Access Framework is used? If you pass persistentDataPath as initialPath, then that's doable. Otherwise you can't achieve this.
     
  34. DavidZobrist

    DavidZobrist

    Joined:
    Sep 3, 2017
    Posts:
    234
    Hi @yasirkula

    I try to run it on the Oculus Quest 2(Android 6.0, API 23) and the Pico 2 Neo (Android 8.0,API 26) I get on both the same issue.

    The file browser is not opening.
    And this error occus:

    Code (CSharp):
    1. 2021.09.01 14:41:14.868 6593 6593 Info UnityMain type=1400 audit(0.0:2823): avc: denied { getattr } for path="/mnt/media_rw" dev="tmpfs" ino=16615 scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:mnt_media_rw_file:s0 tclass=dir permissive=1
    2.  
    System info:
    Using your current version in the assetstore

    Setup:
    Unity 2020.3.8f1
    .NET 4.x IL2CPP
    Write Permission on External (SDCard)

    Additional Info:

    FileBrowser.RequestPermission(); responds with Granted
     
    Last edited: Sep 1, 2021
  35. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    File browser opens in Screen Space-Overlay mode by default. Perhaps it isn't supported in VR. You can put an instance of SimpleFileBrowserCanvas prefab in your scene, change its Render Mode to World Space (or Screen Space-Camera) and position it as you wish then try again.
     
    DavidZobrist likes this.
  36. DavidZobrist

    DavidZobrist

    Joined:
    Sep 3, 2017
    Posts:
    234
    Oh! Thanks this shows up the folders, i adapted the ui.
    And it works.

    Tip sent, enjoy the coffee :D
     
    yasirkula likes this.
  37. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Tip received, thank you!
     
    DavidZobrist likes this.
  38. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Released version v1.5.0 on GitHub: the Skin update! Asset Store version is pending review.

    Screenshot.png
     
  39. TonismoGames

    TonismoGames

    Joined:
    Jun 12, 2018
    Posts:
    111
    Ooo looks amazing
     
    yasirkula likes this.
  40. kyle_lam

    kyle_lam

    Joined:
    Oct 17, 2019
    Posts:
    31
    Its truly impressive to see the support you've been affording people in this thread over the years yasirkula.

    I wonder if you can help me with a simple issue I'm having?
    I have the file browser setup and working. I have identified the part of the script where the load button press is detected. This is where I would like something to happen with the path that is generated (namely load the selected file with another script) except I'm not sure how.

    I thought I could call a function on another script and pass through the path but it would seem that you can't reference other scripts from the FileBrowser.cs script because it sits inside a namespace (namespace SimpleFileBrowser). I think that is what's going on anyway.
    upload_2021-12-6_0-35-18.png

    am I supposed to call to the FileBrowser.cs script from another script instead?

    any help is appreciated!
     
    yasirkula likes this.
  41. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  42. kyle_lam

    kyle_lam

    Joined:
    Oct 17, 2019
    Posts:
    31
    So I am using the example code. While i can see it running the ShowLoadDialogCoroutine it doesn't seem to log the results when the dialogue is closed. am I missing something?

    These debug.logs never fire
    upload_2021-12-6_0-57-14.png
     
  43. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    If you prefer to use WaitForLoadDialog instead of ShowLoadDialog, you must call ShowLoadDialogCoroutine using StartCoroutine.
     
  44. kyle_lam

    kyle_lam

    Joined:
    Oct 17, 2019
    Posts:
    31
    The example code does call the ShowLoadDialogCoroutine with a StartCoroutine in the Start function. but still never returns a success result on dialog close.
     
  45. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    At this point, I'm assuming that you're also calling it like StartCoroutine(ShowLoadDialogCoroutine()) and not just ShowLoadDialogCoroutine(). Honestly, it doesn't make sense for the function to fail. Are there any errors? Does at least the ShowLoadDialog function (which you can uncomment after commenting out ShowLoadDialogCoroutine) work properly?
     
  46. kyle_lam

    kyle_lam

    Joined:
    Oct 17, 2019
    Posts:
    31
    Correct, I am using your example code on the github page at the moment to test with. and it does indeed use StartCoroutine correctly
    upload_2021-12-6_12-48-25.png

    I have a debug.Log("showLoadDialog started") in the body of the coroutine before the yield return that does log to the console.
    upload_2021-12-6_12-59-34.png

    The file browser dialog shows up no problem in game, I am able to go through directories and select files no problem. But when I close the dialog (either by pressing the Load button or Cancel button) it does not seem to return anything.

    There are no errors either.
     
  47. kyle_lam

    kyle_lam

    Joined:
    Oct 17, 2019
    Posts:
    31
    I found the issue.

    I had thought it was necessary to place the SimpleFileBrowserCanvas prefab in the scene for the script to interact with. Removing that from the scene fixes the issue.

    Thanks for the help!
     
    Last edited: Dec 6, 2021
  48. kyle_lam

    kyle_lam

    Joined:
    Oct 17, 2019
    Posts:
    31
    I was able to pass the path to a custom function that loads the data (audio data of selected audio clip) to be played by an audio source. Works great on windows but on android it seems to have an issue with the path. I notice in your documentation that you mention

    "NOTE: On Android Q (10) or later, it is impossible to work with File APIs. On these devices, SimpleFileBrowser uses Storage Access Framework (SAF) to browse the files. However, paths returned by SAF are not File API compatible. To simulate the behaviour of the File API on all devices (including SAF), you can check out the FileBrowserHelpers functions."

    The rest of the documentation doesn't mention which helper function should be used to appropriate the paths generated on android 10 or later. What needs to be done to the outputted path to make it suitable for use?
     
    Last edited: Dec 6, 2021
  49. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You need to use the function that you need from the list of available FileBrowserHelpers functions. For example, in your case, you can copy the file to temporaryCachePath via FileBrowserHelpers.CopyFile.
     
  50. kyle_lam

    kyle_lam

    Joined:
    Oct 17, 2019
    Posts:
    31
    Thanks, I didn't notice that that is already in the example code. I was passing the path over to another script before the CopyFile helper. Passing the path after copyFile works! Thank you