Search code examples
javascripthtmlwindows-runtimewinjs

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


I want to read a file from local storage and upload it via ajax. How is this done?


Solution

  • I managed to figure it out. Here's the code for anyone interested.

    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 } });