写在服务器上使用JavaScript的二进制数据 [英] Write binary data using javascript on the server
本文介绍了写在服务器上使用JavaScript的二进制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用输出服务器端JavaScript(ASP)的PDF文件。我使用的是目前的方法是:
I'm trying to output a PDF using server side javascript (ASP). The current method I'm using is:
xfile=Server.MapPath(lib.fso.GetTempName())
xf=lib.fopen(xfile,"wb");
lib.fwrite(xf,this.buffer);
lib.fclose(xf);
outB = Server.CreateObject("ADODB.Stream")
outB.Type = 1
outB.Open()
outB.LoadFromFile (xfile)
Response.BinaryWrite(outB.Read())
outB.Close()
lib.fso.DeleteFile(xfile);
这工作,但要求写在服务器上的访问。有没有办法做同样的事情,而不写入文件?
This works, but requires write access on the server. Is there a way to do the same thing without writing to a file?
我没有带能够想出如何字符串 this.buffer
转换成字节数组
我可以写,然后使用 Response.BinaryWrite
不先写入文件。
I havn't been able to figure out how to convert the string this.buffer
into a array of byte
that I can then write using Response.BinaryWrite
without writing to a file first.
推荐答案
我的解决方案是使用VBScript。
My solution was to use VBScript.
替换为上述code:
Response.BinaryWrite(StringToMultiByte(this.buffer));
和它添加到该文件的末尾:
and add this to the end of the file:
<script language="vbscript" runat="server">
function StringToMultiByte(S)
Dim i, MultiByte
For i=1 To Len(S)
MultiByte = MultiByte & ChrB(Asc(Mid(S,i,1)))
Next
StringToMultiByte = MultiByte
End function
</script>
这篇关于写在服务器上使用JavaScript的二进制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文