你如何在 winrt html/JavaScript 中上传 filestream/buffer?

how do you upload a filestream/buffer in winrt html/JavaScript?

我想从本地存储中读取文件并通过 ajax 上传。这是怎么做到的?

在大多数浏览器中,您可以使用 FileReader 从文件输入中读取数据。读取数据有多种功能;此示例使用 returns 包含所有字节的 ArrayBuffer 的函数:

<script>
  window.onload = function() {
    document.getElementById('upload').onchange = function(e) {
      var file = e.target.files[0];
      var fileReader = new FileReader();
      fileReader.onload = function(e) {
        var bytes = e.target.result;
        console.log(bytes);
      };
      fileReader.readAsArrayBuffer(file);
    };
  };
</script>
<input type = 'file' id = 'upload' />

我设法弄明白了。这是任何感兴趣的人的代码。

var form = new FormData();
            form.append("data", angular.toJson(message));
            var bytes = new Uint8Array(audio.length); //audio is an IBuffer 
                var dataReader = Windows.Storage.Streams.DataReader.fromBuffer(audio);
                dataReader.readBytes(bytes);
                dataReader.close();

                var media = new Blob([bytes], { type: "application/octet-stream" }); //application/octet-stream or audio/mpeg?
                form.append("attached_files", media, "recording-aac.caf");

            return $http.post(AppSettings.baseUri + "api/sendmessage", form, { headers: { "Content-Type": undefined } });