• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 812
  • Last Modified:

Base64 Encode : Create and write image to server for download later.

I need to convert base64 file encoded from a tif into a TIF file. How would I convert it and write it to a tif file for a user to download?

Thank you!

If you want to see the 64 bit image let me know I will pull it up for you.
0
nfmesa
Asked:
nfmesa
  • 2
  • 2
  • 2
2 Solutions
 
wesbirdCommented:
This works for me on decode: http://www.motobit.com/tips/detpg_Base64/

You may also want to use this technique: http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21368039.html

to server the bytes using the ADODB.Stream object.  You should also modify the content disposition type.

Wes
0
 
nfmesaAuthor Commented:
Wes, after you decode it how do you get it to create the image though?
0
 
wesbirdCommented:
Decode it on the fly and push the bytes directly out as a separate ASP page using the ADODB.Stream object.  You can do this without saving the file if you use an ActiveX DLL.  If it's just ASP you may have to save the file first and load it into the ADODB.Stream object because byte data type is not easily available from ASP/VBscript.

e.g.

Response.ContentType = "image/TIFF"
Response.AddHeader "content-disposition", "attachment; filename=" & strFilename
Response.BinaryWrite bObject

or take a look at this: http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21638573.html

The main thing is to call Response.BinaryWrite.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
nfmesaAuthor Commented:
I used the function from above and I keep getting a bad base64 string. The string is coming right from a USPS xml feed from there servers for a label... Please advice...
0
 
sybeCommented:
Function Base64Encode(ByVal vCode)
    Dim oXML, oNode

    On Error Resume Next

    Set oXML = Server.CreateObject("Msxml2.DOMDocument.3.0")
    Set oNode = oXML.CreateElement("base64")
    oNode.dataType = "bin.base64"
    oNode.nodeTypedValue = vCode
    Base64Encode = oNode.text
    Set oNode = Nothing
    Set oXML = Nothing
End Function


Function Base64Decode(ByVal vCode)
    Dim oXML, oNode

    On Error Resume Next

    Set oXML = Server.CreateObject("Msxml2.DOMDocument.3.0")
    Set oNode = oXML.CreateElement("base64")
    oNode.dataType = "bin.base64"
    oNode.text = vCode
    Base64Decode = oNode.nodeTypedValue
    Set oNode = Nothing
    Set oXML = Nothing
End Function
0
 
sybeCommented:
You might want to experiment with another variant of "Msxml2.DOMDocument.3.0"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now