2014-04-17 2 views
1

고전적인 asp 및 vbscript를 사용하여 이미지를 저장하고 제목에 오류 메시지가 표시되어야합니다.ADODB.Stream - 인수의 형식이 잘못되었거나 범위를 벗어 났거나 서로 충돌했습니다.

나는 모두 참고 번호로 Base64 Encode String in VBScriptConvert hex string (image) to base64 (for browser rendering) in VBScript을 사용했지만 운은 아직 없습니다.

내 프로세스는 다음과 같습니다. 나는 html 5 캔버스가 있고 jquery를 사용하여 이미지를 숨겨진 필드에 저장하고 있습니다.

HTML :

<input type="hidden" id="imageData" name="imageData"> 

JQuery와 :

var image = document.getElementById("canvas").toDataURL("image/png"); 
    image = image.replace('data:image/png;base64,', ''); 
    $('#imageData').val(image); 

내가 데이터를 가져 오는, 그리고 난이 image.replace ('데이터 : 이미지/PNG, 64 기수를', '') 제거했습니다 섹션 그게 문제 인 경우. 다음과 같이

내 VBScript 코드는 다음과 같습니다 심지어는 XML DOM 객체없이 변환을 시도

Function SaveFile(imageData) 
    dim fs,f,mappedpath,filename, userid, fullpathandfilename, imagebinarydata, oStream 
    userid = 12 
    filename = Month(now())&"_"&Day(now())&"_"&Year(now())&"_"&Minute(now())&"_"&Second(now())&".png" 
    mappedpath = Server.MapPath("images/") 
    fullpathandfilename = mappedpath + "\" + filename 

    Const adTypeBinary = 1 
    Const adSaveCreateOverWrite = 2 

    Set oStream = Server.CreateObject("ADODB.Stream") 

    oStream.type = adTypeBinary 
    oStream.open 
    imagebinarydata = Base64Encode(imageData) 
    oStream.write imagebinarydata 

    'Use this form to overwrite a file if it already exists 
    oStream.savetofile fullpathandfilename, adSaveCreateOverWrite 

    oStream.close 

    set oStream = nothing 

    response.write("success") 
End Function 

Function Base64Encode(sText) 
    Dim oXML, oNode 

    Set oXML = CreateObject("Msxml2.DOMDocument.3.0") 
    Set oNode = oXML.CreateElement("base64") 
    oNode.dataType = "bin.base64" 
    oNode.nodeTypedValue =Stream_StringToBinary(sText) 
    Base64Encode = oNode.text 
    Set oNode = Nothing 
    Set oXML = Nothing 
End Function 
'Stream_StringToBinary Function 
'2003 Antonin Foller, http://www.motobit.com 
'Text - string parameter To convert To binary data 
Function Stream_StringToBinary(Text) 
    Const adTypeText = 2 
    Const adTypeBinary = 1 

    'Create Stream object 
    Dim BinaryStream 'As New Stream 
    Set BinaryStream = CreateObject("ADODB.Stream") 

    'Specify stream type - we want To save text/string data. 
    BinaryStream.Type = adTypeText 

    'Specify charset For the source text (unicode) data. 
    BinaryStream.CharSet = "us-ascii" 

    'Open the stream And write text/string data To the object 
    BinaryStream.Open 
    BinaryStream.WriteText Text 

    'Change stream type To binary 
    BinaryStream.Position = 0 
    BinaryStream.Type = adTypeBinary 

    'Ignore first two bytes - sign of 
    BinaryStream.Position = 0 

    'Open the stream And get binary data from the object 
    Stream_StringToBinary = BinaryStream.Read 

    Set BinaryStream = Nothing 
End Function 

하지만 다음 줄에서 줄 바꿈에 유지 :

oStream.write의 imagebinarydata

오류 메시지와 함께 :

ADODB.Stream 오류 '800a0bb9'인수는 다음과 같습니다. 잘못된 유형이거나, 허용 범위를 벗어 났거나, 서로 충돌하고 있습니다.

ADODB.Stream을 사용하려면 추가로 설치해야합니까?

레코드를 삽입하고 업데이트하며 제대로 작동하는 다른 부분 (클래식 ASP 및 vbscript 사용)이 있습니다.

해당 폴더에 대한 쓰기 권한이 있습니다.

어떤 아이디어를 찾고 계십니까?

+0

MSGBOX의 VARTYPE (imageData의)를 수행하고 MSGBOX 끝나면 IsArray (imageData의) MSGBOX ISDATE (imageData의) MSGBOX IsEmpty 함수 (imageData의) MSGBOX ISNULL (imagedata) msgbox IsNumeric (imagedata) msgbox IsObject (imagedata)와 imagebinarydata에 대해서도 –

+0

당신은 혼란 스러워요. 당신의 인코딩은'Base64'로 이미지를 보내고 싶지만 [tag : asp-classic] 끝에서 다시 인코딩하려고하지 않는다면, 이미'Base64'가되고 싶습니다. 바이너리입니다. stream (이 때문에'ADODB.Stream'은 인자가 잘못된 타입이라고 불평합니다). 'Base64Encode()'대신'Base64Decode()'를 사용하면 필요한 것을 얻을 수 있습니다. – Lankymart

+0

더 잘 설명 할 답변을 추가했습니다. – Lankymart

답변

0

이미지 데이터를 Base64으로 두 번 인코딩하면 Base64에서 ADODB.Stream으로 해석 할 수있는 이진 스트림으로 디코딩하는 것이 아니라 손상 될 수 있습니다.


귀하의 프로세스는 다음과 같습니다. >Build Stream from Base64 String - -

Base64 String ->Encode to Base64 String>Save Stream to File


프로세스가 있어야한다;

Base64 String ->Decode to Binary Stream ->Save Stream to File


에서 SaveFile()에서이 줄을 변경해보십시오;

imagebinarydata = Base64Encode(imageData) 

to;

imagebinarydata = Base64Decode(imageData) 

물론 가정 당신은 당신이 제공하는 링크에서 Base64Decode() 기능을 가지고있다. 그렇지 않다면 당신은 이것을 원한다.

Function Base64Decode(ByVal vCode) 
    Dim oXML, oNode 

    Set oXML = CreateObject("Msxml2.DOMDocument.3.0") 
    Set oNode = oXML.CreateElement("base64") 
    oNode.dataType = "bin.base64" 
    oNode.text = vCode 
    Base64Decode = Stream_BinaryToString(oNode.nodeTypedValue) 
    Set oNode = Nothing 
    Set oXML = Nothing 
End Function 

링크

+0

코드를 제안 된대로 변경 했으므로 파일을 저장할 수 있습니다. 이 파일을 열려고하면 파일이 손상되었다고합니다. 이미지는 약 10kb이므로 비어 있지 않습니다. – Sonja

+0

@Sonja 원래 질문에 업데이트 된 코드를 게시 할 수 있습니까? – Lankymart