Air Javascript Save Binary File

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.

BUmP!http://shigeru-nakagaki.com/flex_samples/HTTPMultiService/HTTPMultiServiceSample2/srcview/ index.html

Similar Messages

  • How to increase the camera download speed and save binary file speed

    My camera is pco dimax S1 camea. The interface is cameralink Base.
    The memory is on board.
    I use 1000fps@480*480 resolution to capture 1 sec.
    Then download the images from the on board memory to computer.
    The board in the PC side is NI-1429 board.
    Theory, the cameralink transport speed should be 250MB/S
    In the file format, file size should be (480(H)*480(V)*16bit*1000fps)/8=460.8 MB
    Logically it should be download complete under 2 sec
    But in my program, the real download speed at about 40 framess/s, (480*480*16*40)/8=18.432 MB/S
    (250MB/S)/(18.432MB/S)= 13.85
    The download speed is totally slower 13.8 times.
    I use the SSD and RAID 0 to save the file.
    I did some test as below:
    1. Try to save png or binary file. The speed of binary had a litter faster, but it still doesn't close the 250MB/S.
    2. I try to adjust the resolution from 16bit to 12bit or 8bit to save the image. The download speed still 40 frames/s(18.432MB/S)
    3. I try to use IMAQ Sequence to save the file, but how to add in my program, can anyone help me?
    On the other hand, I also guess may be the structure of my program have an problem cause the download and save speed slow.
    Attached please find the program.
    To see if there are other ways to increase the speed of file written!
    Attachments:
    Imagesavebinary.vi ‏91 KB
    test.png ‏157 KB

    You have to separate your step1 and step2 into two parallel loop.
    If you put the two tasks in one loop, the lower speed task will affect the loop speed.
    So that the program won't achieve the top speed.
    Is continuous acquisition required for your application? Can sequence acquisition or finite acquisition be your workaround?
    The memory handling in continuous acquisition is way a lot more difficult than finite acquisition.
    I would suggest you to figure out how finite acquisition work and then jump into the continuous acquisition application.

  • Decode Base64 and save as binary file

    Hi there,
    I am using Adobe Air 1.5 with JavaScript and want to save a file to my hard
    drive. I get the data from a WebService via SOAP as a Base64 encoded string. A test-string is attached. When I try to decode it with
    the WebKit function "atob()" and try to save this bytes with following code, I can't open the file.
    this.writeFile = function(outputfile, content, append){
    var file =a ir.File.applicationStorageDirectory.resolvePath(outputfile);
    var stream = newa ir.FileStream();
    if (append) {
    stream.open(filea, ir.FileMode.APPEND);
    }else {
    stream.open(filea, ir.FileMode.WRITE);
    try{//Binärdaten
    stream.writeBytes(content0, , content.length);
    }catch(e){//Textdaten
    stream.writeUTFBytes(content);
    stream.close();
    The same happens when I try to open a file from my HDD and read in the bytes. When I decode it to base64, the string is not equal to the string, which is correct.
    I attached a working Base64 string, which I could convert back to a zip-file via a only encoder.
    So my question is, how can I decode a Base64 string and save the binary data to a file?
    Thank you for your help.

    I rewrote the Base64 decoder/encoder to use it with a ByteArray. Here ist the code:
    var byteArrayToBase64 = function(byteArr){
        var base64s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
         var encOut = "";
        var bits;
        var i = 0;
        while(byteArr.length >= i+3){
            bits = (byteArr[i++] & 0xff) << 16 | (byteArr[i++] & 0xff) << 8 | byteArr[i++] & 0xff;
              encOut += base64s.charAt((bits & 0x00fc0000) >> 18) + base64s.charAt((bits & 0x0003f000) >> 12) + base64s.charAt((bits & 0x00000fc0) >> 6) + base64s.charAt((bits & 0x0000003f));
        if(byteArr.length-i > 0 && byteArr.length-i < 3){
            var dual = Boolean(byteArr.length - i - 1);
            bits = ((byteArr[i++] & 0xff) << 16) | (dual ? (byteArr[i] & 0xff) << 8 : 0);
            encOut += base64s.charAt((bits & 0x00fc0000) >> 18) + base64s.charAt((bits & 0x0003f000) >> 12) + (dual ? base64s.charAt((bits & 0x00000fc0) >> 6) : '=') + '=';
        return encOut;
    var base64ToByteArray = function(encStr){
        var base64s = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
         var decOut = new air.ByteArray(); 
        var bits;
        for(var i = 0, j = 0; i<encStr.length; i += 4, j += 3){
            bits = (base64s.indexOf(encStr.charAt(i)) & 0xff) <<18 | (base64s.indexOf(encStr.charAt(i +1)) & 0xff) <<12 | (base64s.indexOf(encStr.charAt(i +2)) & 0xff) << 6 | base64s.indexOf(encStr.charAt(i +3)) & 0xff;
            decOut[j+0] = ((bits & 0xff0000) >> 16);
              if(i+4 != encStr.length || encStr.charCodeAt(encStr.length - 2) != 61){
                   decOut[j+1] = ((bits & 0xff00) >> 8);
              if(i+4 != encStr.length || encStr.charCodeAt(encStr.length - 1) != 61){
                   decOut[j+2] = (bits & 0xff);
        return decOut;

  • How do i disable to pop up asking me if i want to save or cancel the binary file i am trying to download?

    everytime i download a show or movie from the internet a pop up asks me:
    "you have chosen to open xxxxxx which is a: Binary File from: httpxxxxx would you like to save this file - SAVE or CANCEL"
    this never used to happen on the older versions of firefox. it is so annoying - is there any way to turn it off?
    i am running mac os 10.5.8 and no, there is no option to click a 'don't ask me again' feature in the pop-up dialog.

    I'd first try downloading an installer from the Apple website using a different web browser:
    http://www.apple.com/quicktime/download/
    If you use Firefox instead of IE for the download (or vice versa), do you get a working installer?

  • JavaScript To Save A File In Adobe 8?

    Can anyone show me a sample JavaScript to save a file in Adobe 8?
    I tried using "Execute a menu item
    File>Save"
    but it doesn't seem to work in adobe 8.

    Adobe does not consider this a 'safe' menu item and has removed from the list of menu items that can be executed. There is more information available in Acrobat JS API Reference.

  • How to input notes in a binary file used to save continuous DAQ?

    Hello,
    I have a continuous data acquisition vi with trigger. Data is saved in a binary file. I would like to save some comments or notes in this file; I want to be able to read the notes afterwards and the saved data that has to be displayed in charts. I got some examples from NI but they are simple and do not include the continuous data acquisition and reading both the notes and the (dynamic) data.
    Does anyone have examples of binary files with notes and continuous DAQ write and read?
    I've been working on this issue for quite a while and I got stuck...
    Thanks...

    Thank you Emilie.
    I know these examples all right. Now try embedding this into a 'Cont Acq. and Chart - Int. Clk.vi' or any vi that does data acquisition and saves the data in the same file where you wrote the string of comments. And this is not all - how do you read them all back in the right order and right length...
    I have inserted some examples to make you understand better what I am talking about.
    'AcquirePFV_Header.vi' and 'Read_with Header.vi' are only some trials that do not really work correctly.
    Could you or anybody else help me solve this problem?
    Thank you.
    Radu
    Attachments:
    ForNI03.zip ‏1170 KB

  • Want to save the number -9999 into a binary file

    Hello:
    I have this function in which I save different numbers (integers or doubles) into a binary file (with another extension) but when i tried to convert -9999 into bytes and then save it in the file ; it saves -9960 not -9999 as it should. I do not know why.
    This is my function:
    public static void createFile(Double [][] Grid, String txtOutputFile, String[] gridInfoFile){
         Integer[][] intGrid = null ;
         File file = new File(Utils.ChangeFileExt(txtOutputFile, ".myExt"));
         try {
                   FileOutputStream file_out = new FileOutputStream(file);
                   DataOutputStream data_out = new DataOutputStream(file_out);
                   if(gridInfoFile[0].equalsIgnoreCase("1") || gridInfoFile[0].equalsIgnoreCase("1.0")){
                        intGrid = doubleToIntArray(Grid);
              for(int i = 0; i < Grid.length; i++){
                   for(int j = 0; j < Grid[0].length; j++){
                        if(gridInfoFile[0].equalsIgnoreCase("1") || gridInfoFile[0].equalsIgnoreCase("1.0")){
                             Byte byte1, byte2;                         
                             byte1 = new Integer (intGrid[i][j] / 256).byteValue();
                             byte2 = new Integer(intGrid[i][j] - (intGrid[i][j] / 256)).byteValue();
                             data_out.write(byte2);
                             data_out.write(byte1);
                        if(gridInfoFile[0].equalsIgnoreCase("2") || gridInfoFile[0].equalsIgnoreCase("2.0")){
                             ByteArrayOutputStream byte_out = new ByteArrayOutputStream ();
                             DataOutputStream data_out2 = new DataOutputStream (byte_out);
                             data_out2.writeFloat(Grid[i][j].floatValue());
                             byte[] bArray = byte_out.toByteArray();
                             data_out.write(bArray[3]);
                             data_out.write(bArray[2]);
                             data_out.write(bArray[1]);
                             data_out.write(bArray[0]);
              }//fin for
              data_out.close();
              } catch (FileNotFoundException e) {
                   e.printStackTrace();
              } catch (IOException e) {
                   e.printStackTrace();
    I had already tried data_out.writeFloat, write, writeInt, etc without any success.
    If someone knows the answer , please let me know, will appreciate that. Thank you for your help
    magnasound

    Since you are using DataOutputStream, why not use some of its more helpful methods, like writeInt?

  • For the ignoran t what is a Binary file? Assume I should save it.

    Automatically updates have been added when I went into Firefox to go to Ocado. It tells me I have chosen to open 'Firefox Setup 6.0.exe' which is a binary file fro: http://mirror.ibcp.fr and ask if I would like to save this file. Am I correct in saying I suppose I should save it. The other option is to cancel. I would like an explanation as to what the two options mean exactly. This happened just now so cannot answer with options given below

    Just let iMovie manage it.
    When an application saves a document it's a bad idea to delete or empty the old one first and then write the new one. What if something goes wrong? A power outage or what ever.
    The proper way is to keep the old (original) file until the new one has been completely written and THEN delete it. It seems as iMovie keeps the original under the <projectname>.BAK name until the new file is written.

  • Why does my computer ask me to save firefox 4 as a binary file?

    My computer asks me to upgrade to firefox 4 which I attempted to do. However when I try to do this a box pops up asking me to save firefox 4 as a binary file. Then nothing else happens. The next day my computer will ask me again to upgrade to firefox 4. I try again but again my computer will ask me to save firefox as a binary file. What is the problem?

    You need to update to Pages 4.1. If you haven't moved or renamed Pages then you'll be able to update Pages by running Software Update on your Mac. Or if you purchased Pages from the Mac App Store then you can launch the Store and click on Updates.

  • Itunes won't download, binary file won't save to computer.

    Every time I click on the "Download Now" button, I am able to select what folder I want to download the binary file to.
    Once I click save, nothing else happens. I am taken to the "Thank you for downloading itunes" screen, but there is no record of my download anywhere, and the file is simply not saving.

    So weird...I don't know why so many folks have this problem. Why won't the silly file download from Apple? When I click "save file" absolutely nothing happens. A dialogue box should pop up asking me where to save it.
    My solution was to finally download it from one of the many file servers. I used one called "filehorse" and it downloaded right away.
    How can one use their nifty iOS device if they can't install itunes on their computer?!
    I tried the recommended "fixes", one of which included deleting the "temp" folder (which was not so easy to delete, required booting to safe mode command prompt) but made no difference. This was all using Firefox. IE is the only other browser on my computer, which seems to be permanently broken (most sites do not show properly even after using IE's "reset" feature).
    I refuse to install Chrome, I tried it once and it sucked. Hopefully Apple will fix this silly issue so that next time I need to download iTunes, I can do it. Thank you!

  • Unable to save Flash/shockwave/reader  & air to a EXE file to install later

    It is me or what, I work in a enironment where we have to download and update client computer with Adobe Flash , Air etc. But In order to do this, we need to first save the file to the local drive and then "RUN AS administrator"  === No i am unable to do that in Microsofte IE or Firefire fox.
    Any anyone tell me how to force it to manually ask me to save it to a file or disable the autoinstall/launch
    many thanks
    Sammy
    [email protected]
    [email protected]
    nd

    Download your Flash installer files from http://www.adobe.com/products/flashplayer/fp_distribution3.html
    Concerning Adobe AIR, you have to ask in that forum.
    P.S. don't publish your email address in a public forum - spammers will be happy to pick them up!

  • Bug in LV8 : 'Save for previous version' and 'Write to Binary File' VI

    Hello
    I am using LabVIEW 8's revamped 'Write to Binary File' VI with a 'TRUE' boolean constant wired to the optional 'prepend array or string size?' to write non-trivial structures to a binary file. I then read the file with the 'Read from Binary File' VI and everything is fine. I don't wire anything to the 'file (use dialog)' input (don't know if this can help).
    However, after saving my VI for LabVIEW 7.1, I cannot read the binary files created with the LV7 version of the VI anymore. After examining the LV7 converted version of the VI, there is a 'FALSE' boolean constant that is wired to the equivalent of the 'prepend array or string size' input, which breaks the binary format that is expected.
    The attached files are LV8 and 'saved for LV7' versions of a dummy VI that writes an array of 5 integers into a binary file. To test the bug, start LV8, open the LV8 version, run it and create a 'test-lv8.bin' file, then open the LV7 version, run it and create a 'test-lv7.bin' file. Check the content of the two files : the size of the array is indeed missing from the 'test-lv7.bin' file, which can be assimilated as a bug in my opinion.
    I think I found another one too : if in LV8 I wire the 'cancelled' boolean output of the 'Open/Create/Replace file' to the selector of a case structure, the 'converted to LV7' version VI will have an error, saying the Case Structure selector is not wired.
    Could someone please confirm these are indeed bugs ?
    Thanks in advance and have a nice day.
    Eric Batut
    Attachments:
    Test Binary File v7-v8 LV7.vi ‏15 KB
    Test Binary File v7-v8 LV8.vi ‏7 KB

    I'm using LV8.6 and need to read a .bin file created in MATLAB. This file obviously does not contain the 4 byte header that LabVIEW prepends .bin files with. So when I use Read from Binary File, I get no data (I'm trying to read an array of doubles). I've tried making my .bin file both in native and big-endian format and changing the representation (double, int64, float64) but none of this works. I noted that if I create the same array in a .bin file in LabVIEW and wire a FALSE to the "prepend array or string size?", my VI for reading .bin files can't read this file either.
    Any work-arounds here?
    (I'll try attaching my write & read VI's)
    Attachments:
    ReadWriteBinFile.zip ‏19 KB

  • Binary file save - bug in lv8 for MAC ?

    Hi,
    Using LV8 on Mac OSX, I found a bug concerning binary file saving (attached file).
    Write an array of double in a binary file. Read it back.
    If you used little endian,ok. If you used Big-endian, result is wrong (but no error).
    Could a mac user replicate ?
    Boris Matrot
    Attachments:
    bin_file_save_lv8_mac.vi ‏14 KB

    Just as an additional data point, everything works fine under Windows.
    (As a workaround, have you tried flattening the data for writing? I don't have a MAC, so I cannot test.)
    Message Edited by altenbach on 01-19-2006 12:41 PM
    LabVIEW Champion . Do more with less code and in less time .

  • When I try to download the newest version of Firefox, it pops up with a box saying do you want to save this binary file with something like daimaijin.mirror in the address. Is this a safe thing to do or is it spyware or something?

    If I cancel it and try it again, the same binary file box pops up with a different address.

    Mozilla has download mirror websites around the globe and uses them to "balance" the downloads of Firefox so users don't need to "wait in line" for their download.
    Here's a listing of those mirrors. <br />
    http://www.mozilla.org/community/mirrors.html

  • Link in Adobe AIR JavaScript app is incorrectly opening the app in the default browser

    I have a couple of links in my Adobe AIR JavaScript app that are part of the app's UI, which when clicked are causing the app to be loaded into a new tab in my default browser.
    This is only happening with two links (Save and Cancel on a form), and not all links in my UI.  The two links that are having the issue are defined in an external HTML file that I load a runtime and connect to the DOM.  The links that are defined in the main HTML file that is loaded when the app starts up do not have this problem.
    Here is how I am loading the template and plugging it into the DOM
    var win = document.createElement("div");
    var f = air.File.applicationDirectory.resolvePath("lib/partials/edit_form.html");
    var fs = new air.FileStream();
    fs.open(f, air.FileMode.READ);
    var content = fs.readUTFBytes(fs.bytesAvailable);
    fs.close();
    var template = new Template(content);
    win.innerHTML = template.evaluate(data);
    document.body.insertBefore(win, document.body.firstChild);
    The links themselves are coded like this:
    <a href="#" id="save_button" onclick="return false;"></a>
    <a href="#" id="cancel_button" onclick="return false;"></a>
    I am using the Prototype JS library to observe the 'click' event for each of these links like so:
    $('save_button').observe('click', onSave);
    $('save_button').observe('click', onCancel);
    This app shows content created by users, which can contain links to external web sites.  To get the external links to open in the browser (as opposed to inside my Adobe AIR window), I am doing the following in a script tag in the head of my main HTML file:
    window.htmlLoader.navigateInSystemBrowser = true
    I've found that if I set window.htmlLoader.navigateInSystemBrowser = false, then the issue with the Save and Cancel links described above goes away.  However, I need to have window.htmlLoader.navigateInSystemBrowser = true so that external links in the user content open up in the browser, not in Adobe AIR.
    Another piece of evidence is that the Save and Cancel links only incorrectly open a browser the first time you click on them after launching the app.  Subsequent clicks work fine and do not have the issue.
    Any ideas on why the links that are plugged into the DOM after app start up have this issue, and only the first time you click on them?

    Not sure where this comes from, but I suspect it has something to do with the security restrictions that AIR has in place, related to dynamic JS evaluation after the document is loaded.
    Make sure you read http://help.adobe.com/en_US/air/html/dev/WS5b3ccc516d4fbf351e63e3d118666ade46-7f0e.html#WS 5b3ccc516d4fbf351e63e3d118666ade46-7ef8
    For example, I've spotted the two onclick="return false;" you have in your code. The evaluation of the onclick attribute after the page loaded event would fail in AIR.

Maybe you are looking for

  • Save error when exporting to PNG in Illustrator using a Macbook with Yosemite

    Anybody experience the issue of png being saved with "/" in the beginning of the file name when exporting to png in Illustrator? This only happens when I use my mac not my PC. Due to the save error my PC cannot identify the files and when the files a

  • How to set todays date in message date input field in uix

    Hello everybody, Im using jdeveloper 9015+adf+uix I am having an input form and in that i want to set the date input field with the current date(default value). Does anybody of you know how I should do this. Any help is appreciated, Thanks in advance

  • Multiple pages

    i have many pdfs i want to put in one file to print how do i add multiple pages to my pdf file im trying to make a book and i can only get one page on it at a time thanks so much

  • Fillable PDF Email not working

    I built a fillable PDF form located here http://www.depts.ttu.edu/recsports/sportclubs/forms/Filliable%20Pre-Trip.pdf and when I click on the submit by email button I get a pop up asking me to choose my mail client. However many of my users click on

  • MM03 Material master display F4 help is not available

    Dear All..                 For one particular user MM03 Material master display F4 help is not available even i have press the push button on material text the help is not popup. Even authorization already exist  for that user material master display