-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accessing the parent of FileSystemFileHandle #38
Comments
The ability to get the Parent of an item is a common FileSystem API point |
This was discussed in WICG/file-system-access#193 (and WICG/file-system-access#373, which seems like the same request as 2) This comment provides context as to why we've been hesitant to provide this method, though the arguments there are more relevant to files picked outside of the OPFS. I wonder if something like what's proposed in WICG/file-system-access#378 would be more useful than just access to the parent, since combining this with the |
The comments you point to discuss a number of issues that don't apply to OPFS (since you don't get handles from a picker); we always know and can easily return the parent of a file or directory and there are no permission issues. Yes, direct path access (like in #378) would definitely be useful for reasons outside of this issue. You could implement parent() as resolve, strip the last entry, and the getdirectoryhandle using #378. This would work; it might be more expensive though, since it requires walking to the root and then back again. |
Why does it have to be so complicated for such a simple requirement as requesting parent folder(s) of files. My js application saves location of local video file in order to access it upon subsequent import of a json file. I export something like: localhost:8080/Assets/Media/Video/myvideo.mp4, but I need now to provide sub-folders inside the "Video" folder in order to better manage media content. I must know the sub-folder name (which is a parent directory of media file) in order to save it as a string, alongside the media file's name like so: "ParentFolder/myvideo.mp4". The File System Access API must provide for such an option -- I'm certainly not going to have to force user to write -- via a dialog box - which parent folder he/she/it is using, at each and every media list iteration. SOLUTION: If the API provides the parent folder name of video file that I can include in my json export string, then when I import the json file back into my app, the saved string "ParentFolder/myvideo.mp4" will be appended to "localhost:8080/Assets/Media/Video/" located in my app in order for the video to be playable at any time, on user demand, for as long as the video still exists in that folder, of course. So I'm not asking for much, this API allows more flexibility, but stops short of providing the basic feature I request: Knowing the parent folder of a media file, or, knowing the relative path of sub-folders leading to the media file without exposing the whole local url of the media file. Am I missing something here? I have implemented the following sample located at https://web.dev/patterns/files/open-one-or-multiple-files/#the-modern-way and would sure love to know where I must insert code that exposes the parent folder of media file. I am not using this API for writing, moving, deleting, creating, etc folders and/or files, I simply need to read the "ParentFolder/file-name.ext" portion of a local url, is that possible? Thanks in advance for swift reply. |
@danavangard It's (maybe unfortunately) not possible to get information about the parent folder of a file for the reasons outlined in WICG/file-system-access#193 (comment). On top, it could potentially also be revealing private information. Imagine a file hierarchy like For your concrete problem, I think what might work is ask for access to a directory via const directoryHandle = await showDirectoryPicker({
startIn: 'videos',
}); The relevant pattern is explained in How to open a directory. 💡 Bonus tip: I maintain a library called Back to @orlovushek's original points:
|
@tomayac Awesome! I will try the |
There is no method to request the parent of FileSystemFileHandle.
Some use cases:
FileSystemDirectoryHandle.removeEntry()
. This will allow the files opened with PWA (viafile_handlers
) to be removed from within PWA.The text was updated successfully, but these errors were encountered: