Base64 Encode a ZIP file using Classic ASP and VB Script

混江龙づ霸主 提交于 2021-01-27 18:31:32

问题


I have a zip file, which contains one CSV file.

I need to Base64 encode this zip file to send to eBay (using their API).

I used this website: http://www.opinionatedgeek.com/DotNet/Tools/Base64Encode/ which works nicely, I upload my zip file and it returns a base64 encoded string which eBay likes.

I need to do what this website does, but using Classic ASP and VB Script.

I already have a base64 encode function, from here: http://www.motobit.com/tips/detpg_base64encode/ so I don't need a script for that. This function takes a parameter, so I need to turn my zip file into a string (I think) to pass into this function.

I have tried using ADODB.Stream and the LoadFromFile method, but the string it returns, after base64 encoding, doesn't match that from the opinionated geek website and isn't accepted by eBay.

This is what I've tried:

Dim objStream, strFileText

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.LoadFromFile Server.MapPath("myzipfile.zip")

strFileText = Base64Encode(objStream.Read)
Response.Write strFileText

objStream.Close
Set objStream = Nothing

Can anyone help..?

Thanks!


回答1:


This is now solved...

I was missing the BinaryToString function between the stream output and the base64 encode.

Now I use:

strFileText = Base64Encode(BinaryToString(objStream.Read))

Where the new function is...

Function BinaryToString(Binary)
  Dim I, S
  For I = 1 To LenB(Binary)
    S = S & Chr(AscB(MidB(Binary, I, 1)))
  Next
  BinaryToString = S
End Function

The output from this now matches the output from the opinionated geek tool.

Thanks to ulluoink for pointing me in the right direction!



来源:https://stackoverflow.com/questions/17446676/base64-encode-a-zip-file-using-classic-asp-and-vb-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!