locked
WinJS.xhr - UPLOAD PROGRESS

    Question

  • AM WRONG or LOOKS LIKE the function WinJS.xhr has a PROGRESS callback that is USELESS since you can't really use to update the bytes uploaded?

    IS SO.. My question is HOW INCOMPETENTE is the TEAM behind it which thought that it would be COOL to have a POST function to upload data and NO WAY to tell the progress of this data upload or download?

    This is unheard of for anyone i tell!

    Anyone?

    Alan. 

    Friday, February 21, 2014 11:06 PM

Answers

  • WinJS.xhr is just a simple wrapper for the standard JS XMLHttpRequest function, and so its bound by those limits. Its basic purpose is to turn the XMLHttpRequest API model into a promise model. It communicates everything it gets from XMLHttpRequest, which you can see in the base.js file of WinJS.

    If you want a more capable API, use Windows.Web.Http.HttpClient in Windows 8.1, or the background transfer API in Windows.Networking.BackgroundTransfer. They generally provide much richer progress reporting. If you're doing a large enough transfer that progress reporting is important, I highly recommend the BackgroundTransfer API because those operations will continue even when an app is suspended, which is not true of other HTTP requests.

    Kraig

    Author, Programming Windows Store Apps with HTML, CSS, and JavaScript, Second Edition, a free ebook from Microsoft Press. First edition (for Windows 8) also available.


    Friday, February 21, 2014 11:59 PM

All replies

  • WinJS.xhr is just a simple wrapper for the standard JS XMLHttpRequest function, and so its bound by those limits. Its basic purpose is to turn the XMLHttpRequest API model into a promise model. It communicates everything it gets from XMLHttpRequest, which you can see in the base.js file of WinJS.

    If you want a more capable API, use Windows.Web.Http.HttpClient in Windows 8.1, or the background transfer API in Windows.Networking.BackgroundTransfer. They generally provide much richer progress reporting. If you're doing a large enough transfer that progress reporting is important, I highly recommend the BackgroundTransfer API because those operations will continue even when an app is suspended, which is not true of other HTTP requests.

    Kraig

    Author, Programming Windows Store Apps with HTML, CSS, and JavaScript, Second Edition, a free ebook from Microsoft Press. First edition (for Windows 8) also available.


    Friday, February 21, 2014 11:59 PM
  • If you need help please post a clear and polite description of the scenario you are trying to achieve, what code are you currently using, and how does that code not meet your needs.

    --Rob

    Saturday, February 22, 2014 12:05 AM
    Owner
  • Thank you very much Kraig.. You explained it all!
    Saturday, February 22, 2014 10:27 PM
  • Am i wrong or the BackgroundTransfer. only works with ASPX because it only uploads StorageFiles? I couldn't make my PHP script to save the file and there's no way i am going to change my whole server to use aspx
    Sunday, February 23, 2014 1:43 AM
  • No, that's not the case. The BackgroundTransfer API works with HTTP requests on the backside. StorageFile is a WinRT construct only--think of it as an abstraction for a filename. It's how you simply reference where downloaded data should be stored and how you point to the source of upload data.

    If you look at the BackgroundUploader, for example, you'll see that it has a method property that specifies HTTP PUT, HTTP POST, or FTP STOR, so those are the ways in which your server--regardless of how it's written--will receive the data. In short, because the API works over HTTP straight up, it can work with any service including PHP. You can also set HTTP headers if you want (the setRequestHeader method), provide credentials, do multipart uploads, etc., all of which happens over HTTP.

    Chapter 4 of my second preview ebook talks about the API in more detail than you get in the docs. And no need to change your server :)

    Sunday, February 23, 2014 4:19 AM
  • Hey Kraig.. would you check out my last question here:

    http://social.msdn.microsoft.com/Forums/windowsapps/en-US/8e8cfcdc-8f56-404b-bd10-f74743aab93e/share-target-problem-when-sharing-storageitems?forum=winappswithhtml5#8e8cfcdc-8f56-404b-bd10-f74743aab93e

    is this an unsolved issue for javascript? 

    Saturday, March 01, 2014 8:39 PM