Date:  06/14/2010 06:27:54 AM Msg ID:  004173
From:  James Williams Thread:  004172
Subject:  Re: return file with base64 encoding
I would just use the filetostr() function, I have never had any problems with its conversion and I have used it for PDF's, Word docs, images you name it.
Sent by Gia Luc on 06/10/2010 07:51:33 AM:
Hello
I am trying to return a file to the client browser.  To avoid any problems caused by binary to character conversion, I'm not using FILETOSTR().  Instead, I encode the file to base64, then add a http header to say that the file is encoded in base64 and send the file to the browser.
Unfortunately, it does not seem to work properly, the browser simply saves the file as the base64 encoded version, rather than decoding it and then saving the file.  What to do ?  Thanks for any help you can provide.
Here is my code: 
*/' Set up the base64 library in order to encode the file.
oBase64 = createobject("Base64Lib.Base64")

*/' Base64 encode the file to string
lcFileContent = oBase64.EncodeFromFile("c:\transfer\test.pdf")

*/' Specify file name in the http header.
Response.AddHeader("Content-Disposition", "attachment; filename=test.pdf")

*/' Specify size so that the browser's progress bar works properly
Response.AddHeader("Content-Length",ALLTRIM(STR(LEN(lcFileContent))))

*/' Specify the type of encoding used, so the client knows how to decode.
Response.AddHeader("Content-Transfer-Encoding","base64")

Response.ContentType = "application/pdf"

*/' Send file to browser.
Response.Write(lcFileContent)

*/' Release the base64 object.
RELEASE oBase64