我一直在尝试使用经典 ASP 从服务器端将 Base64 文件保存为图像。我想要的是将文件自动保存到特定位置并给它一个文件名,现在我可以很好地编码它的这方面。但是,如果不先在浏览器上渲染,我就无法获取保存图像的代码。这对我来说不起作用,因为我使用的脚本将是自动导出并且没有用户输入。
代码如下,在网页中呈现并询问用户将图像保存在哪里。只是重申一下,我需要它自动保存(无需用户输入)
base64String ="base64 code goes here - Wont add it as its huge amount of text"
Set tmpDoc = Server.CreateObject("MSXML2.DomDocument")
Set nodeB64 = tmpDoc.CreateElement("b64")
nodeB64.DataType = "bin.base64" ' stores binary as base64 string
nodeB64.Text = Mid(base64String, InStr(base64String, ",") + 1) ' append data text (all data after the comma)
vehicleAuditName= "Audit1"
With Response
.Clear
.ContentType = "image/png"
.AddHeader "Content-Disposition", "attachment; filename=" & vehicleAuditName & ".png"
.BinaryWrite nodeB64.NodeTypedValue 'get bytes and write
.end
End With
请您参考如下方法:
使用 adodb.stream 对象将图像存储在服务器端,如下所示:
dim bStream : set bStream = server.CreateObject("ADODB.stream")
bStream.type = adTypeBinary
call bStream.Open()
call bStream.Write( binData )
call bStream.SaveToFile( FullName, adSaveCreateOverWrite)
call bStream.close()
set bStream = nothing