2

我一直在尝试使用经典的 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
4

3 回答 3

3

使用 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
于 2013-01-31T15:23:45.533 回答
2

接收 base64 字符串的服务器端代码如下,请注意,这是取自工作系统的代码,因此有一些变量(例如 carreg / auditdate)用作为创建的文件命名的唯一标识符:

function convBase64 (convVal, getCarReg, convType, AuditDate, AuditReference)
    base64String = convVal
    carReg = (UCase(getCarReg))
    carReg = (Replace(getCarReg," ",""))

    AuditDate= CDate(AuditDate) 
    ConvAuditDate = ((DatePart("d",AuditDate))& "_" & (DatePart("m",AuditDate)) & "_" & (DatePart("YYYY",AuditDate)))

    select case convType
        Case "Sig1"
        FileNameSuffix = "AuditorsSignature"
        Case "Sig2"
        FileNameSuffix = "BodyShopSignature"
        Case "Car"
        FileNameSuffix = "DamageCanvas"
    end select
    ImageFileName =  FileNameSuffix & "-" & carReg & "-" & ConvAuditDate & ".jpg"

        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)


        dim bStream : set bStream = server.CreateObject("ADODB.stream")
        bStream.type =  1
        call bStream.Open()
        call bStream.Write( nodeB64.NodeTypedValue )
        call bStream.SaveToFile(Server.Mappath("NoneVehicleImages/" & AuditReference & "/" &  ImageFileName), 2 )
        call bStream.close()
        set bStream = nothing
        convBase64 = "\\iis_fdg$\AuditExport\NoneVehicleImages\"  & AuditReference & "\" & ImageFileName
end function
于 2014-09-19T13:27:47.667 回答
-3

由于安全原因,您不能这样做。如果网页可以在没有任何用户交互的情况下随机选择在我们的本地系统上存储文件的位置,就会出现混乱。

于 2013-01-31T15:22:04.683 回答