2 Replies Latest reply on Oct 18, 2009 1:12 PM by dzony

    Air Javascript Save Binary File

    mopenstein

      I'm trying to download and save binary file to the local disk. I've spent all morning trying to get this to work bu am stumped

       

                  function saveFile(outData) {
                          try    {
                              stream = new air.FileStream();
                              stream.open(currentFile, air.FileMode.WRITE);
                                  stream.writeBytes(outData, 0, outData.length);
                              stream.close();
                              document.title="Finished"
                          }  catch(error) {
                              alert(error);
                          }

                  }

       

                  function downloadMP3() {
                     var req = new XMLHttpRequest();
                     req.onreadystatechange = function() {
                          if (req.readyState == 4) {
                              saveFile(req.responseText);
                          } else if(req.readyState == 3) {
                              document.title="Downloading...";
                          }
                      };
                     
                      req.open('GET', downloadFile, false);
                      req.overrideMimeType('text/plain; charset=binary');
                      req.send(null);
                  }

       

      This is where I'm at now and it's been one long road to get there. I assumed that I could just request the file from the net and then just save it but that would be too easy.

       

      Any help would be appreciated, thanks.