Parsing Base64 encoding

Discussion in 'ASP .Net Web Services' started by LP, May 2, 2005.

  1. LP

    LP Guest

    A web service returns base64 encoded data. The goal is to parse it and store
    it into binary file with .dat extension. This file is then will be used by a
    custom program to produce diagrams. As far as I know base64 data is not any
    known graphic format, from what I understand it's just encoded stream of
    bytes. Which I need to write to .dat file. Where to start? any links or
    suggestions?

    Thank you.
     
    LP, May 2, 2005
    #1
    1. Advertising

  2. LP

    Bruce Wood Guest

    Have you tried this?

    Declare the element in question in the XML schema for the Web Service
    as being "base64Binary".

    Load the results of the Web Service call into a DataSet. The resulting
    DataColumn should have a type of Byte and the byte array it contains
    should be the binary version of the base 64 encoding in the XML.

    Failing that, I did write my own base64 encoding class that I could
    pass along.
     
    Bruce Wood, May 2, 2005
    #2
    1. Advertising

  3. LP

    laimis Guest

    If you care just saving the bytes into the file, use FileStream class
    provided by .net. It provides a Write method that accepts a byte array
    as a parameter (byte array would be your base64 data).

    If you need to decode base64 encoded data, simple use
    Convert.ToBase64String() method which is also provided by the framework.
    base64 is nothing special, just bytes which values are limited by the
    set of characters that belong to base64 encoding.

    Does that answer your question?
     
    laimis, May 2, 2005
    #3
  4. LP

    laimis Guest

    If you care just saving the bytes into the file, use FileStream class
    provided by .net. It provides a Write method that accepts a byte array
    as a parameter (byte array would be your base64 data).

    If you need to decode base64 encoded data, simple use
    Convert.ToBase64String() method which is also provided by the framework.
    base64 is nothing special, just bytes which values are limited by the
    set of characters that belong to base64 encoding.

    Does that answer your question?
     
    laimis, May 2, 2005
    #4
  5. As the other posters have hinted at, you just need to use the Convert
    class and a way to write the data to disk (FileStream works nicely).

    Assuming your base64 data is in a string named receivedBase64string, and
    you want to write it to the file c:\received.data

    using System.IO;


    byte[] rawData = Convert.FromBase64String(receivedBase64string);
    using (FileStream fs = new FileStream(
    @"c:\received.dat",
    FileMode.Create))) {
    fs.Write(rawData, 0, rawData.Length);
    }


    Joshua Flanagan
    http://flimflan.com/blog


    LP wrote:
    > A web service returns base64 encoded data. The goal is to parse it and store
    > it into binary file with .dat extension. This file is then will be used by a
    > custom program to produce diagrams. As far as I know base64 data is not any
    > known graphic format, from what I understand it's just encoded stream of
    > bytes. Which I need to write to .dat file. Where to start? any links or
    > suggestions?
    >
    > Thank you.
    >
    >
     
    Joshua Flanagan, May 3, 2005
    #5
  6. LP

    LP Guest

    That's easier than I thought, thanks everyone!


    "Joshua Flanagan" <> wrote in message
    news:%...
    > As the other posters have hinted at, you just need to use the Convert
    > class and a way to write the data to disk (FileStream works nicely).
    >
    > Assuming your base64 data is in a string named receivedBase64string, and
    > you want to write it to the file c:\received.data
    >
    > using System.IO;
    >
    >
    > byte[] rawData = Convert.FromBase64String(receivedBase64string);
    > using (FileStream fs = new FileStream(
    > @"c:\received.dat",
    > FileMode.Create))) {
    > fs.Write(rawData, 0, rawData.Length);
    > }
    >
    >
    > Joshua Flanagan
    > http://flimflan.com/blog
    >
    >
    > LP wrote:
    > > A web service returns base64 encoded data. The goal is to parse it and

    store
    > > it into binary file with .dat extension. This file is then will be used

    by a
    > > custom program to produce diagrams. As far as I know base64 data is not

    any
    > > known graphic format, from what I understand it's just encoded stream of
    > > bytes. Which I need to write to .dat file. Where to start? any links or
    > > suggestions?
    > >
    > > Thank you.
    > >
    > >
     
    LP, May 3, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mm

    Help with base64 encoding

    mm, Feb 13, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    1,759
  2. -intl.com

    Base64 Encoding with streams.

    -intl.com, Mar 2, 2006, in forum: Java
    Replies:
    10
    Views:
    21,888
    Greg R. Broderick
    Mar 3, 2006
  3. wenmang
    Replies:
    3
    Views:
    567
    Dennis E. Hamilton
    Sep 5, 2003
  4. Sridhar Anupindi
    Replies:
    0
    Views:
    609
    Sridhar Anupindi
    May 25, 2004
  5. Replies:
    14
    Views:
    2,771
    aruna
    Jul 9, 2007
Loading...

Share This Page