base64 enc/dec problem

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default base64 enc/dec problem

    I'm having a problem encoding a file (image) into base64, and then
    converting it back from base64 and saving it.

    I've tried several ways, but whenever i open the new image.. it is always
    corrupt.

    Here is the base coding I'm trying to get working

    Imports System.IO

    Dim fs As FileStream

    Dim fswrite As FileStream

    Dim oByte() As Byte

    fs = New System.IO.FileStream("C:\18.jpg", _

    System.IO.FileMode.Open, _

    System.IO.FileAccess.Read)



    ReDim oByte(fs.Length)

    Dim b64String As String



    b64String = System.Convert.ToBase64String(oByte, 0, fs.Length)

    fswrite = File.Create("C:\test1.jpg", 1024)

    Dim info As Byte() = New UTF8Encoding(True).GetBytes(b64String)

    fswrite.Write(info, 0, info.Length)

    fswrite.Close()

    fs.Close()


    PCH Guest

  2. Similar Questions and Discussions

    1. Base64.Encode in AS1
      Hi, know i know chances are really slim on this one but i'm currently working with a Base64 encdoing in AS2. Now its not my original code which...
    2. Problem with Base64 encoding a MS Word Document
      I am trying to Base64 encode a MS Word document on CF 7. However, when I try to decode and save the file and open it in word, it only shows raw...
    3. Java Base64 encoding
      When I specify a username and password within a CFHTTP tag does Cold Fusion automatically Java Base64 encode these values or is it something you...
    4. decoding a base64 file?
      Hello folks, If I encode a file with MIME::Base64 with the following script, encode_base64.pl. The question is; how do I decode the file? I...
    5. base64 code
      Hi Alan, Thanks for your help. Also I know for a fact my client is not a spammer! But thanks for the warning anyway! "Alan Ames"...
  3. #2

    Default Re: base64 enc/dec problem


    "PCH" <pch12@hotmail.com> wrote in message
    news:Omaoeb$PDHA.704@tk2msftngp13.phx.gbl...
    > I'm having a problem encoding a file (image) into base64, and then
    > converting it back from base64 and saving it.
    >
    > I've tried several ways, but whenever i open the new image.. it is always
    > corrupt.
    >
    First you were never reading the input file. Second you were saving the
    base64 encoded string to the output file. Here:

    Dim fs As FileStream
    Dim fswrite As FileStream
    Dim oByte() As Byte
    fs = New System.IO.FileStream("C:\18.jpg", _
    System.IO.FileMode.Open, _
    System.IO.FileAccess.Read)
    ReDim oByte(fs.Length)
    fs.Read(oByte, 0, fs.Length)
    Dim b64String As String
    b64String = System.Convert.ToBase64String(oByte, 0, fs.Length)
    fswrite = File.Create("C:\test1.jpg", 1024)
    Dim info As Byte() = System.Convert.FromBase64String(b64String)
    fswrite.Write(info, 0, info.Length)
    fswrite.Close()
    fs.Close()

    David


    David Browne Guest

  4. #3

    Default Re: base64 enc/dec problem

    ah that Read call!
    fs.Read(oByte, 0, fs.Length)

    Thanks for the info!



    "David Browne" <davidbaxterbrowne no potted [email]meat@hotmail.com[/email]> wrote in
    message news:%23wydej$PDHA.3880@tk2msftngp13.phx.gbl...
    >
    > "PCH" <pch12@hotmail.com> wrote in message
    > news:Omaoeb$PDHA.704@tk2msftngp13.phx.gbl...
    > > I'm having a problem encoding a file (image) into base64, and then
    > > converting it back from base64 and saving it.
    > >
    > > I've tried several ways, but whenever i open the new image.. it is
    always
    > > corrupt.
    > >
    > First you were never reading the input file. Second you were saving the
    > base64 encoded string to the output file. Here:
    >
    > Dim fs As FileStream
    > Dim fswrite As FileStream
    > Dim oByte() As Byte
    > fs = New System.IO.FileStream("C:\18.jpg", _
    > System.IO.FileMode.Open, _
    > System.IO.FileAccess.Read)
    > ReDim oByte(fs.Length)
    > fs.Read(oByte, 0, fs.Length)
    > Dim b64String As String
    > b64String = System.Convert.ToBase64String(oByte, 0, fs.Length)
    > fswrite = File.Create("C:\test1.jpg", 1024)
    > Dim info As Byte() = System.Convert.FromBase64String(b64String)
    > fswrite.Write(info, 0, info.Length)
    > fswrite.Close()
    > fs.Close()
    >
    > David
    >
    >

    PCH Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139