Base64使用经典ASP和VB脚本对ZIP文件进行编码 [英] Base64 Encode a ZIP file using Classic ASP and VB Script
问题描述
我有一个zip文件,其中包含一个CSV文件.
I have a zip file, which contains one CSV file.
我需要对这个zip文件进行Base64编码以发送到eBay(使用其API).
I need to Base64 encode this zip file to send to eBay (using their API).
我使用了以下网站: http://www.opinionatedgeek.com/DotNet/Tools/Base64Encode/效果很好,我上传了zip文件,它返回了eBay喜欢的base64编码的字符串.
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.
我需要做这个网站,但是要使用Classic ASP和VB脚本.
I need to do what this website does, but using Classic ASP and VB Script.
我已经有一个base64编码功能,来自这里: http://www.motobit.com/tips/detpg_base64encode/,因此我不需要脚本.该函数需要一个参数,因此我需要将zip文件转换为字符串(我认为)才能传递给该函数.
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.
我尝试使用ADODB.Stream和LoadFromFile方法,但是在base64编码之后,它返回的字符串与自以为是的极客网站的字符串不匹配,因此eBay不接受.
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.
这是我尝试过的:
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..?
谢谢!
推荐答案
现在已解决...
我在流输出和base64编码之间缺少BinaryToString函数.
I was missing the BinaryToString function between the stream output and the base64 encode.
现在我使用:
strFileText = Base64Encode(BinaryToString(objStream.Read))
新功能在哪里...
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.
感谢ulluoink向我指出了正确的方向!
Thanks to ulluoink for pointing me in the right direction!
这篇关于Base64使用经典ASP和VB脚本对ZIP文件进行编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!