0

Windows 8 アプリで作業しているときに、次のようなものを使用して File オブジェクトを開いて参照を取得できることに気付きました。

// Markup
<input type='file' id='myfile'/>

// JavaScript
var fInput = document.getElementById('myFile');
fInput.onchange = function (e) {
    var dataSource = e.target;
    var file = dataSource.files[0]; // object of type 'File'
}

ただし、[参照] ボタンを押さなくても、ユーザーにファイル ピッカーを表示したいと考えています。そこで、次のように FilePicker クラスを使用してみました。

var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.pickSingleFileAsync().then(function (file) {
    // in this case, file is a 'StorageFile' object
});

問題は、どうにかして代わりにオブジェクトをpickSingleFileAsync返すことができるかということです ?FileStorageFile

4

1 に答える 1

1

MSApp.createFileFromStorageFileを使用します。ここでのドキュメント エラーは無視してください。これは、API が行うことの逆を示します。

// TODO - more code is required here to initialize file open picker. 
// refer the file picker sample
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.pickSingleFileAsync().then(function (storageFile) {
    // ignore when file pick is cancelled
    if (!storageFile)
        return;
    var file = MSApp.createFileFromStorageFile(storageFile);
});
于 2013-05-30T04:31:03.277 に答える