Base64编码保存,使用传统ASP的图像 [英] Save Base64 to an image using Classic ASP

查看:859
本文介绍了Base64编码保存,使用传统ASP的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试一个base64文件保存为使用传统的ASP从服务器端的图像。我要的是它的自动保存文件到特定的位置,并给它一个文件名,现在我很好的编码它的这一方面。不过,我不能得到code保存图像,而不在浏览器中第一次呈现。这不会为我工作,因为我使用将是一个自动导出脚本并没有用户输入。

code如下尚未呈现在网页,并要求用户在哪里保存图像。只是重申我需要它自动保存(没有用户输入)

  base64String =的base64 code到这里 - 惯于把它添加为大量的文本设置tmpDoc =的Server.CreateObject(MSXML2.DomDocument)
设置nodeB64 = tmpDoc.CreateElement(B64)
nodeB64.DataType =bin.base64的商店二进制为base64字符串
nodeB64.Text = MID(base64String,INSTR(base64String,)+ 1)'附加数据文本(逗号之后的所有数据)vehicleAuditName =Audit1随着响应
   。明确
   .ContentType =图像/ PNG
   .AddHeader内容处置,附件;文件名=&放大器; vehicleAuditName&安培; 巴纽
   .BinaryWrite nodeB64.NodeTypedValue获得字节写
   。结束
结束与


解决方案

使用ADODB.Stream对象的图像存储在服务器端,像这样:

 昏暗bStream:设置bStream =的Server.CreateObject(的ADODB.Stream)bStream.type = adTypeBinary调用bStream.Open()调用bStream.Write(binData)调用bStream.SaveToFile(全名,adSaveCreateOverWrite)调用bStream.close()
设置bStream =什么

I have been trying to save a base64 file as an image from server side using classic ASP. What I want is it to autosave the file to a specific location and give it a filename, Now I am fine coding that aspect of it. However I can't get the code to save the image without first rendering on a browser. This isn't going to work for me as the script I am using will be an automatic export and have no user input.

Code follows as yet that renders in the webpage and asks the user where to save the image. Just to reiterate I need it to auto save (no user input)

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

解决方案

use an adodb.stream object to store the image on the server side like so:

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

这篇关于Base64编码保存,使用传统ASP的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆