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;

Similar Messages

  • How can I extract certain pages from my document and save as another file?

    How can I extract certain pages from my document and save as another file?

    You would need Adobe Acrobat to do that, not Adobe Reader.

  • How to change and save a new file in Edge web Lumira server for Team ?

    Hi Lumira folks,
    I've installed SAP Lumira 1.0, Edge edition and View a sample 'Dairy Wholesaler-Sample"
    I'd like to change it and save as new file, but "Save" button is disabled and when I put my mouse over the button,
    it says "Save Option is disabled in this version".
    Is there any idae how to change and save as a new file in Lumira Edge ?
    Many Thanks.
    JH

    I've just found the reason as below.
    http://scn.sap.com/community/lumira/blog/2015/03/20/lumira-server-for-teams-edge-edition-version-compatibility
    The current version of Lumira
    server for teams is 1.0. This version uses Lumira 1.22 as its 'engine' as this
    was the version of Lumira Desktop that was shipped at the same time.
    Hence with the current Lumira
    version compatibility; namely that a newer version of the product can open an
    older document, but an older version cannot open a newer document, care must be
    taken when deploying Lumira server for teams.
    Lumira server for teams is only
    compatible with Lumira desktop 1.22. If you intend to deploy Lumira server for
    teams, ensure your desktop users do not move to a later version of the desktop.
    Content created in a later version of Lumira desktop can be uploaded and shared
    via Lumira server for teams, but it cannot be viewed or edited online in the
    browser.
    Ensure desktop users disable the
    auto update capabilities in the desktop preferences, and set the update to
    none.

  • I have a Macbook Air (july 2012) with OS X 10.8.3  installed.  I have dvds with .vob files and have Quicktime Version 10.2 (603.12).  I can't play the DVDs.  Thereare some features of QT that I like, e.g. precise frame selection and save as .png file-help

    I have a Macbook Air (july 2012) with OS X 10.8.3  installed.  I have dvds with .vob files and have Quicktime Version 10.2 (603.12).  I can't play the DVDs.  There are some features of QT that I like, e.g. precise frame selection and save as .png file-help.  Am I missing some Apple software?  I thought QT for Mountain Lion could convert the .vob files - is there some setting that I have missed?
    Any suggestions that preserves a simple workflow much appreciated.

    arthur wrote:
    Perian is here: Perian - The swiss-army knife of QuickTime® components
    Perian will be retired soon.

  • How can I edit and save a raw file in jpeq and open it in windows live photo gallery

    how can I edit and save a raw file in ps elements 10 and open it in windows live photo gallery?

    Change to 8 bit mode before clicking the Open Image button, then jpeg will become available as a choice.
    Click to view image

  • I cannot download and save an eps file in Adobe Photoshop Elements 12

    I am unable to open and save an eps file in Adobe Photoshop Elements 12

    No, EPS is one of the formats that adobe removed support for, starting with PSE 11.

  • Way to edit and save .AC3 audio files?

    Anyone know if there is a way to edit and save .AC3 audio files in Audition 3?

    Every time you open any coded file at all in Audition, you lose quality if you resave it in anything other than an uncompressed format. With most formats, what is even worse is saving them in a different compressed format, because you end up with twice as many different coding artefacts.
    What you need to understand is that all of these formats are distribution formats, not editing ones. The basic principle is that you work in an uncompressed format until the last possible moment - ie, distribution. And that, ideally, is the only time you use a compressed format at all. So if you want to use something that's compressed, you uncompress it once, and don't recompress until you absolutely have to.

  • I have a problem during the collect data and save it in file with the HP8753C

    Hello,
    I'm using the "HP8753 collect and display data.vi" with the functionnality "save" in file (.txt or xls).
    When I'm using it to collect and save data one time to time, I have no problem. But when I would like to use it to collect and save several data with a structure "For", the HP8753 status will become blocked and the collect and save data in file is disable.
    The only function "collect data" with a structure "for" is Ok but will become not OK with the option "save" in file. Why, please ?

    Hello,
    Thank you for contacting National Instruments.
    It sounds like your instrument is "hanging" or "freezing" when you try to read and save data from it in LabVIEW.
    I took a look at the context help for that particular VI. It appears that if you attempt to read data from the HP8753 while it is also taking measurements, it can cause the instrument to hang. This may be the problem you are experiencing.
    Look over your program and ensure that the instrument is not trying to take new measurements as you read data from it in LabVIEW. Sequence structures may be useful in this regard. If you are still experiencing problems, however, let me know.
    Matthew C
    Applications Engineer
    National Instruments

  • 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

  • How can i control NI-6115 to collect data from 2 channels and save as 2 files?

    I want to program NI-6115 card to collect data from 2 channels and save the two data into two different filenames that i specified?
    How do i write in labview codes?

    Calibur,
    LabVIEW includes a number of examples that demonstrate how to acquire analog input data and write it to disk. Dependent upon the type of file you would like to use, I would suggest that you examine one of the following examples:
    Cont Acq to File (binary).vi
    Cont Acq to File (scaled).vi
    Cont Acq to Spreadsheet File.vi
    With regards to writing each channel's data to a separate file, you will need to use the Index Array function to generate two 1-D arrays, each containing data for one channel. These arrays can then be written to separate files using two Write File functions.
    Good luck with your application.
    Spencer S.

  • Export to Excel and Save as Static File

    Hello all,
    When I export to excel from SharePoint 2013, and save the file, the data remains dynamic in that if I update the list in SharePoint it will update the data in Excel. This is great and I use it in a few places, but I also need to capture a point in time and
    save the exported Excel file as static data (i.e. Export to Excel, and Save as the Q3 Report). How can I save the file as static/remove the dynamic link so I just have the data at the time of export?
    Thanks!
    K.
    Personal Blog: http://thebitsthatbyte.com

    Hi Kelly,
    According to your description, my understanding is that you want to export to excel as a static file.
    In SharePoint, when you export list to excel, it works as a one-way sync. It can sync data from SharePoint to Excel. If you don’t want to sync the data from SharePoint, you can copy the data from the exported excel file to a new excel, then save the new
    excel file.
    Best Regards,
    Wendy
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Wendy Li
    TechNet Community Support

  • File Server - File size\type search and save results to file

    I already have a vb script to do what I want on our file server, but it is very inefficient and slow.  I was thinking that a powershell script may be more suitable now but I don't know anything about scripting in PS.  So far the vb code that I
    have works, and I am not the one who wrote it but I can manipulate it to do what I want it to.  The only problem is, when I scan the shared network locations it stops on some files that are password protected and I don't know how to get around it.  If
    someone else knows of a PS script to go through the file system and get all files of a certain type or size (right now, preferably size) and save the file name, size, path, owner and dates created\modified please point me to it and I can work with that.  If
    not, could I get some help with the current script that I have to somehow get around the password protected files?  They belong in a users' HOME directory so I can't do anything with them.  Here is my code:   
    'Script for scanning file folders for certain types of files and those of a certain size of larger'
    'Note: Script must be placed locally on whichever machine the script is running on'
    '***********VARIABLES FOR USE IN SCRIPT***********'
    'objStartFolder - notes the location of the folder you wish to begin your scan in'
    objStartFolder = "\\FileServer\DriveLetter\SharedFolder"
    'excelFileName - notes the location where you want the output spreadsheet to be saved to'
    excelFileName = "c:\temp\Results_Shared.xls"
    '**********END OF VARIABLES**********'
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    fileName = objFSO.GetFileName(path)
    'beginning row and column for actual data (not headers)'
    excelRow = 3
    excelCol = 1
    'Create Excel Spreadsheet'
    Set objExcel = CreateObject("Excel.Application")
    Set objWorkbook = objExcel.Workbooks.Add()
    CreateExcelHeaders()
    'Loop to go through original folder'
    Set objFolder = objFSO.GetFolder(objStartFolder)
    Set colFiles = objFolder.Files
    For Each objFile in colFiles
    Call Output(excelRow) 'If a subfolder is met, output procedure recursively called'
    Next
    ShowSubfolders objFSO.GetFolder(objStartFolder)
    'Autofit the spreadsheet columns'
    ExcelAutofit()
    'Save Spreadsheet'
    objWorkbook.SaveAs(excelFileName)
    objExcel.Quit
    '*****END OF MAIN SCRIPT*****'
    '*****BEGIN PROCEDURES*****'
    Sub ShowSubFolders(Folder)
    'Loop to go through each subfolder'
    For Each Subfolder in Folder.SubFolders
    Set objFolder = objFSO.GetFolder(Subfolder.Path)
    Set colFiles = objFolder.Files
    For Each objFile in colFiles
    Call Output(excelRow)
    Next
    ShowSubFolders Subfolder
    Next
    End Sub
    Sub Output(excelRow)
    'convert filesize to readable format (MB)'
    fileSize = objFile.Size/1048576
    fileSize = FormatNumber(fileSize, 2)
    'list of file extensions currently automatically included in spreadsheet report:'
    '.wav, .mp3, .mpeg, .avi, .aac, .m4a, .m4p, .mov, .qt, .qtm'
    If fileSize > 100 then'OR objFile.Type="Movie Clip" OR objFile.Type="MP3 Format Sound" _ '
    'OR objFile.Type="MOV File" OR objFile.Type="M4P File" _'
    'OR objFile.Type="M4A File" OR objFile.Type="Video Clip" _'
    'OR objFile.Type="AAC File" OR objFile.Type="Wave Sound" _'
    'OR objFile.Type="QT File" OR objFile.Type="QTM File"'
    'export data to Excel'
    objExcel.Visible = True
    objExcel.Cells(excelRow,1).Value = objFile.Name
    objExcel.Cells(excelRow,2).Value = objFile.Type
    objExcel.Cells(excelRow,3).Value = fileSize & " MB"
    objExcel.Cells(excelRow,4).Value = FindOwner(objFile.Path)
    objExcel.Cells(excelRow,5).Value = objFile.Path
    objExcel.Cells(excelRow,6).Value = objFile.DateCreated
    objExcel.Cells(excelRow,7).Value = objFile.DateLastAccessed
    excelRow = excelRow + 1 'Used to move active cell for data input'
    end if
    End Sub
    'Procedure used to find the owner of a file'
    Function FindOwner(FName)
    On Error Resume Next
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery _
    ("ASSOCIATORS OF {Win32_LogicalFileSecuritySetting='" & FName & "'}" _
    & " WHERE AssocClass=Win32_LogicalFileOwner ResultRole=Owner")
    For Each objItem in colItems
    FindOwner = objItem.AccountName
    Next
    End Function
    Sub CreateExcelHeaders
    'create headers for spreadsheet'
    Set objRange = objExcel.Range("A1","G1")
    objRange.Font.Bold = true
    objExcel.Cells(1, 1).Value = "File Name"
    objExcel.Cells(1, 2).Value = "File Type"
    objExcel.Cells(1, 3).Value = "Size"
    objExcel.Cells(1, 4).Value = "Owner"
    objExcel.Cells(1, 5).Value = "Path"
    objExcel.Cells(1, 6).Value = "Date Created"
    objExcel.Cells(1, 7).Value = "Date Modified"
    End Sub
    Sub ExcelAutofit
    'autofit cells'
    Set objRange = objExcel.Range("A1")
    objRange.Activate
    Set objRange = objExcel.ActiveCell.EntireColumn
    objRange.Autofit()
    Set objRange = objExcel.Range("B1")
    objRange.Activate
    Set objRange = objExcel.ActiveCell.EntireColumn
    objRange.Autofit()
    Set objRange = objExcel.Range("C1")
    objRange.Activate
    Set objRange = objExcel.ActiveCell.EntireColumn
    objRange.Autofit()
    Set objRange = objExcel.Range("D1")
    objRange.Activate
    Set objRange = objExcel.ActiveCell.EntireColumn
    objRange.Autofit()
    Set objRange = objExcel.Range("E1")
    objRange.Activate
    Set objRange = objExcel.ActiveCell.EntireColumn
    objRange.Autofit()
    Set objRange = objExcel.Range("F1")
    objRange.Activate
    Set objRange = objExcel.ActiveCell.EntireColumn
    objRange.Autofit()
    Set objRange = objExcel.Range("G1")
    objRange.Activate
    Set objRange = objExcel.ActiveCell.EntireColumn
    objRange.Autofit()
    End Sub
    David Hood

    Accessing Excel through automation is bvery slow no matter what tool you use.  Scanning a disk is very slow for all tools.
    Since Vista all system have a search service that catalogues all major file itmes like size, extension, name and other attributes.  A search of a 1+Tb  volume can return in less that a second if you query the search service.
    You can easily batch the result into Excel by writ4ing to a CSV and opening in Excel. Use a template to apply formats.
    Example.  See how fast this returns results.
    #The following will find all log files in a system that are larger than 10Mb
    $query="SELECT System.ItemName, system.ItemPathDisplay, System.ItemTypeText,System.Size,System.ItemType FROM SystemIndex where system.itemtype='.log' AND system.size > $(10Mb)"
    $conn=New-Object -ComObject adodb.connection
    $conn.open('Provider=Search.CollatorDSO;Extended Properties="Application=Windows";')
    $rs=New-Object -ComObject adodb.recordset
    $rs.open($query, $conn)
    do{
    $p=[ordered]@{
    Name = $rs.Fields.Item('System.ItemName').Value
    Type = $rs.Fields.Item('System.ITemType').Value
    Size = $rs.Fields.Item('System.Size').Value
    New-Object PsObject -Property $p
    $rs.MoveNext()
    }Until($rs.EOF)
    ¯\_(ツ)_/¯

  • Upload and save an Excel file from a local machine to SAP

    I am looking for a transaction which allows me to upload an Excel file from a local machine to SAP and save this file (the users should be able to edit the file in SAP afterwards).
    Then I would like to open and read the data from the file with the help of a function module which works as a background job.
    Unfortunately, I cannot use the application server because our users do not have the authorization to save files on it. Besides, the application server is not able to process Excel files.
    Thank you in advance.
    Stephan Klumpp

    Hi Stephan,
    You can do this using OLE technology. Bu you will have performance issues.
    Can you check the below demo programs? It has similar functionality. I am able to create excel sheet from sap and also able to save the data in the sap.
    SAPRDEMOEXCELINTEGRATION
    SAPRDEMOEXCELINTEGRATION2
    Please also check the below rograms for more help.
    SAPRDEMOACTIVEXINTEGRATION
    SAPRDEMODOCUMENTCONTAINER
    SAPRDEMODOCUMENTCONTAINER2
    Thanks
    Ramakrishna

  • Upload attachements from Windows and Save them to File System

    Hi
    We are upgrading to 11.5.10, using Database 10g r2. Can any one help me to upload attachement from a PC and save to a Unix file system instead of database. We are using forms 6i. Please help.

    Hi
    We are upgrading to 11.5.10, using Database 10g r2. Can any one help me to upload attachement from a PC and save to a Unix file system instead of database. We are using forms 6i. Please help.

  • Working with folders and save metadata to file compatability.

    when i edit in developer within lightroom, then move from the 'previous import' list to the folders which hold different projects by dragging them into the folders i have imported from the hard disk, it saves only the original files, and not my new edits.
    do i have to batch export everything i edit in lightroom to be able to use it in non adobe applications??
    i tried save metadata to file for these images, and then in finder they are no longer available for quickview (spacebar or command y) and finder quits. futhermore when these files, with the updated metadata, are dropped into an iwork file, they are not recognised as jpeg's anymore. but do work in photoshop, and i assume other adobe applications because the embedded metadata was designed to be compatible with adobe.
    how can i have the 'develop' editing i am doing in lightroom transfer to the folders i want to have these images saved in without laboriously exporting them and having saved each image twice? does lightroom have a way i can do this?

    If you're largely preparing images for the web, you simply export a batch from LR at the appropriate size and quality, in sRGB space, with or without metadata as you choose. Nothing laborious about it.
    Are you starting with JPEGs or RAW images?
    The bug in Leopard is known, but you also cannot expect the Finder to show what edits you have made in LR until the images are rendered out, as they are in an Export.

Maybe you are looking for

  • How do I change the appleid emailaddress on my iphone?

    I`ve reduced my emailaccounts and the one I had on my Iphone as appleid I changed on apples page on the internet to a emailaddress I actually am using. Now I cant change it on the Iphone! I`ve tried to reenter it on apples page (I hadnt/havent yet de

  • How do I access documents in iCloud.

    I can't find an iCloud icon & iCloud.com doesn't work? It tells me to set up iCloud but I already did that.

  • Running 2nd display... (question)

    Hey everyone. My brother has a Powermac G5 dual 1.8 with 4GB RAM and it's currently got an old AGP graphics card in - I think it's a Radeon 9800 Pro. Anyway, he's picked up another cinema display and wants to use 2 screens for editing however his gra

  • New FCP effects causing crash

    With the latest version of FCP we've been given some cool new effects that used to live only in Motion. My problem is, every time I try to apply one, FCP crashes. Any ideas on what might be the cause or how I might go about troubleshooting it? G5 dua

  • Can i use webserver other than that is provided by LabVIEW to view remote panels?

    How to view remote panels using webserver (not inbuilt of labVIEW)? Is it possible to communicate with other webserver? if yes which VIs to be used?