locked
Download html file with stream

    Question

  • I'm downloading blobs with the code below, but would like to adapt it for html files.  I have my WinJs.xhr call responseType set to "document".  Is it possible to stream the html file?  I'm getting an error using .msDetachStream

    function writeDocToFile(result) {
        var doc = result.response;
         Windows.Storage.ApplicationData.current.localFolder.createFileAsync(fileName, Windows.Storage.CreationCollisionOption.replaceExisting
    ).then(
        function (file) {
         file.openAsync(Windows.Storage.FileAccessMode.readWrite).then(
        function (output) {
         var input = doc.msDetachStream();
                        Windows.Storage.Streams.RandomAccessStream.copyAsync(input, output
    ).then(
       function () {
         output.flushAsync().done(function () {
         input.close();
         output.close();
         });
       });
      });
     });
    }


    • Edited by hxnwx Thursday, March 19, 2015 4:17 PM edit
    Thursday, March 19, 2015 4:16 PM

All replies

  • Hi hxnwx,

    What is the error message while using msDetachStream?

    As I know if we set the responseType as "document", that means the file is an XML Document Object Model (XML DOM) object instead of the stream, ref:xhr function

    Base the documentation of msDetachStream, it accept IInputStream from Blob or MSStream, I think that's why msDetachStream give you error if your xhr return object is not a Blob.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, March 20, 2015 5:39 AM
    Moderator
  • This is the error:

    JavaScript runtime error: Object doesn't support property or method 'msDetachStream'.

    So I can't use stream with a "document" type.

    Is there another method to write the xhr result to the storage file?

    Friday, March 20, 2015 3:11 PM
  • Yes, looks like msSaveBlob can help with that if your treat your file as a Blob, see this: Saving files locally using Blob and msSaveBlob

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 23, 2015 9:07 AM
    Moderator
  • The issue is not with blobs.  I am streaming blobs with no problems.  I would like to save an html file result (from winjs.xhr call) to html file type.  Basically write the result to html file, not necessarily stream it.  Is this possible? 

    Monday, March 23, 2015 3:44 PM