简体   繁体   English

你可以从它的路径访问一个选择的 StorageFile 吗? - UWP

[英]Can you access a picked StorageFile from its Path? - UWP

I need to be able to access a file from it's path in a UWP application.我需要能够从 UWP 应用程序中的路径访问文件。

The file is first selected by the user using OpenFilePicker.该文件首先由用户使用 OpenFilePicker 选择。 I then need to pass this file on to an FFmpeg wrapper that sets its input from a file path.然后我需要将此文件传递给 FFmpeg 包装器,该包装器从文件路径设置其输入。 Currently, I get access denied errors for any file that is outside the apps local storage (as expected).目前,对于应用程序本地存储之外的任何文件(如预期的那样),我都会收到拒绝访问错误。

FileOpenPicker filePicker = new FileOpenPicker();
filePicker.ViewMode = PickerViewMode.Thumbnail;
filePicker.FileTypeFilter.Add("*");


var file = await filePicker.PickSingleFileAsync();


FFMpegArguments
   .FromInputFiles(file.Path.ToString())

Is there a way to retain the apps permission to this file when it is accessed by a path string (file.Path.ToString()) rather then a storage file instance?当通过路径字符串 (file.Path.ToString()) 而不是存储文件实例访问该文件时,有没有办法保留应用程序对该文件的权限? Have been looking into FutureAccessList but that seems to only provide another storage file instance later rather then allow for path access to the same file.一直在研究 FutureAccessList 但这似乎只是稍后提供另一个存储文件实例,而不是允许路径访问同一文件。 I'd like to not enable broad file system access as I only need access to a single file that has already been picked by the user.我不想启用广泛的文件系统访问,因为我只需要访问用户已经选择的单个文件。

Thanks!谢谢!

This is excepted behavior.这是例外行为。 UWP apps are not allowed to use Path by default. UWP 应用默认不允许使用路径。 UWP apps have a restricted broadFileSystemAccess capability . UWP 应用程序具有受限的广泛文件系统访问功能 This capability allows UWP apps to access to all the files in the system.此功能允许 UWP 应用程序访问系统中的所有文件。 But you could only use the Storage API to get files via path.但是您只能使用存储 API通过路径获取文件。

For your scenario, you might need to check if the FFMpegArguments object has other methods to create instances like using steam.对于您的场景,您可能需要检查 FFMpegArguments object 是否有其他方法来创建实例,例如使用 steam。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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