如果我使用getFileAsync而不是Picker.pickSingleFileAsync,则无法从FutureAcc

Cannot retrieve file from FutureAccessList if I use getFileAsync instead of Picker.pickSingleFileAsync

本文关键字:pickSingleFileAsync FutureAcc Picker getFileAsync 如果      更新时间:2023-09-26

我有一个应用程序,以两种方式检索文件:一种使用文件选择器,另一种直接使用路径。在这两种情况下,我都获得文件,将其添加到未来访问列表中,并将令牌保存在数组中。稍后在应用程序中,我使用令牌使用futureAccessList.getFileAsync检索文件。现在,第二部分,即使用令牌代码返回文件在两种情况下都是相同的,所以它必须在我将其添加到未来访问列表的方式中,因为它在我使用filepicker时有效,但在我直接使用路径时不起作用。

Filepicker add code

    // Create the picker object and set options
    var openPicker = new Windows.Storage.Pickers.FileOpenPicker();
    openPicker.viewMode = Windows.Storage.Pickers.PickerViewMode.thumbnail;
    openPicker.suggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.musicLibrary;
    // Select MIDI files only
    openPicker.fileTypeFilter.replaceAll([".mp3"]);
    // Open the picker for the user to pick a file
    openPicker.pickSingleFileAsync().then(function (file) {
        if (file) {
            // Application now has read/write access to the picked file
            WinJS.log && WinJS.log("Picked file: " + file.name, "sample", "status");
            // Store the file to access again later
            var listToken = Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.add(file);
            // Save the file mapping. If it exists, overwrite.
            fileMappings[padId] = { padNumber: padId, audioFile: listToken };
        }
        else {
            // The picker was dismissed with no selected file
            WinJS.log && WinJS.log("Operation cancelled.", "sample", "status");
        }
    });

直接路径添加代码

    Windows.Storage.KnownFolders.musicLibrary.getFileAsync("filename.mp3").then(function (file) {
        if (file) {
            // Application now has read/write access to the picked file
            WinJS.log && WinJS.log("Picked file: " + file.name + ", full path: " + file.path, "sample", "status");
            // Store the file to access again later
            var listToken = Windows.Storage.AccessCache.StorageApplicationPermissions.futureAccessList.add(file);
            // Save the file mapping. If it exists, overwrite.
            fileMappings['pad0'] = { padNumber: 'pad0', audioFile: listToken };
        }
        else {
            // Could not get access to the file
            WinJS.log && WinJS.log("File unavailable!", "sample", "status");
        }
    });

我个人觉得(Windows.Storage.KnownFolders.musicLibrary.getFileAsync)这行没有给我读写权限,只是读,这可能是搞砸它的原因。这是msdn上的一个相关帖子。这是一个c# -MediaElement问题,但密切相关。你知道这里有什么问题吗?如果它与权限相关,我如何指定我需要r-w访问?我认为在appxmanifest中指定功能就足够了。如果有人需要,我可以在这里添加文件检索代码。谢谢你的宝贵时间。

[Windows RT应用程序使用Javascript。]

代码是正确的。这是WinRT API中的一个bug。我在系统的那部分工作,并在这个主题上提交了一个bug。

相关文章:
  • 没有找到相关文章