Writing binary data using javascript on the server

I am trying to output a PDF using javascript (ASP) on the server side. 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 without writing to a file?

I was not able to figure out how to convert the string this.bufferto array of bytewhich I can write with Response.BinaryWritewithout writing the file first.

+3
source share
2 answers

My solution was to use VBScript.

replace the above code with:

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>
0
source

Why not just use: -

Response.Write(this.buffer)

, (I.e., , Locale, VBScript), Response.Write , StringToMultiByte.

, . , , , BinaryWrite. .

+1

Source: https://habr.com/ru/post/1722524/


All Articles