Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用vbscript经典asp上载图像_Javascript_Jquery_Ajax_Jquery Mobile_Vbscript - Fatal编程技术网

Javascript 使用vbscript经典asp上载图像

Javascript 使用vbscript经典asp上载图像,javascript,jquery,ajax,jquery-mobile,vbscript,Javascript,Jquery,Ajax,Jquery Mobile,Vbscript,我正在构建我们的移动应用程序的一部分,我试图让点击选择一个文件,他们选择一张照片或用相机拍摄一张。在用户选择图片后,我遇到了问题,我想将其上载到我们的图像数据库中,因此我使用ajax将其发布到asp页面,然后尝试解码base64字符串,然后将其上载到数据库中。我们的数据库只接受二进制数据,我真的很难完成这一步,任何帮助都将不胜感激 html 选择文件 上传 将图片构建为基本64字符串的javascript var hiddenbutton = $("#hiddenButton");

我正在构建我们的移动应用程序的一部分,我试图让点击选择一个文件,他们选择一张照片或用相机拍摄一张。在用户选择图片后,我遇到了问题,我想将其上载到我们的图像数据库中,因此我使用ajax将其发布到asp页面,然后尝试解码base64字符串,然后将其上载到数据库中。我们的数据库只接受二进制数据,我真的很难完成这一步,任何帮助都将不胜感激

html

选择文件
上传
将图片构建为基本64字符串的javascript

   var hiddenbutton = $("#hiddenButton");
hiddenbutton.hide();
$('#page').live('pageinit', function(){
    $("#chooseFile").click(function(e){
        e.preventDefault();
        $("input[type=file]").trigger("click");
    });
    $("input[type=file]").change(function(){
        var file = $("input[type=file]")[0].files[0];
        $("#preview").empty();
        displayAsImage3(file, "preview");
        $info = $("#info");
        $info.empty();
        if (file && file.name) {
            $info.append("<li>This is just a preview click the upload button below to upload the picture</li>")
        }
        if (file && file.name) {
            $info.append(hiddenbutton.show());
        }
        $info.listview("refresh");

    });
});

function displayAsImage3(file, containerid) {
    if (typeof FileReader !== "undefined") {
        var container = document.getElementById(containerid),
            img = document.createElement("img"),
            reader;
        container.appendChild(img);
        reader = new FileReader();
        reader.onload = (function (theImg) {
            return function (evt) {
                theImg.src = evt.target.result;
            };
        }(img));
        reader.readAsDataURL(file);
    }




}
var hiddenbutton=$(“#hiddenbutton”);
hiddenbutton.hide();
$('#page').live('pageinit',function(){
$(“#选择文件”)。单击(函数(e){
e、 预防默认值();
$(“输入[type=file]”)。触发器(“单击”);
});
$(“输入[type=file]”)。更改(函数(){
var file=$(“输入[type=file]”[0])。文件[0];
$(“#预览”).empty();
显示图像3(文件“预览”);
$info=$(“#info”);
$info.empty();
if(file&&file.name){
$info.append(
  • 这只是一个预览,单击下面的上载按钮上载图片) } if(file&&file.name){ $info.append(hiddenbutton.show()); } $info.listview(“刷新”); }); }); 函数displayAsImage3(文件、容器ID){ if(文件读取器的类型!=“未定义”){ var container=document.getElementById(containerid), img=document.createElement(“img”), 读者; 子容器(img); reader=newfilereader(); reader.onload=(函数(theImg){ 返回函数(evt){ theImg.src=evt.target.result; }; }(img)); reader.readAsDataURL(文件); } }
  • 我的ajax正在捕获该元素并将其传递到我的asp页面

       function PicUpload () {
        var strDocType;
        var strImage;
        var strPath;
        var strPicExtension;
        var strDOTInfo;
        var strFileType;
        var strFileID;
        var image;
        var imgsomething;
    
    
    
    
     strDocType = "<%=strDocType%>";
     strImage = ($('img')[0].src);
     strPicExtension = strImage.substring(11, 14)
     strDOTInfo = $("#txtDotInformation").val();
     strFileType = "";
     strFileID = "";
     image = "";
     imgsomething = "";
    
    
    
    
    
    
    if (strPicExtension == "jpe") {
        strFileType = "image/jpeg"
    }
    
    if (strPicExtension == "gif") {
        strFileType = "image/gif"
    }
    
    if (strPicExtension == "png") {
        strFileType = "image/png"
    }
    
    
    if (strPicExtension != "jpe") {
        strPath = strImage.substring(22);
    }
    else {
        strPath = strImage.substring(23);
    }
    
    
    if (strDOTInfo == "") {
            alert("You must enter the DOT Information")
            $("#txtDotInformation").focus();
            return false;
            }
    
        if (strDocType == "CALLUPLOAD") {
            var strCallID;
            var strDOTID;
            var strDOTSizeCode;
            var intDOTDateCode;
    
            strCallID = "<%=strCallID%>";
            strDOTID = strDOTInfo.substring(0,2);
            strDOTSizeCode = strDOTInfo.substring(2,4);
            intDOTDateCode = strDOTInfo.substring(4,8);
    
            if (strCallID == "") {
            alert("There has to be a call ID")
            return false;
            }
    
    
          image =  btoa(strPath);
    
    
    
    
    
    
    
    
            jQuery('#pics').html ('<img src="/GYGlobal/images/icons/ajax-  loader.gif"> Uploading Pic . . .');
                    jQuery.ajax({
                    type: "POST",
                    url: "/tools/document_picture_ajax.asp",
                    data: 'hidAjaxAction=PicUpload&hidDOTID='+strDOTID+'&hidDOTSizeCode='+strDOTSizeCode+'&hidDOTDateCode='+intDOTDateCode+'&hidCallID='+strCallID+'&hidFileType='+strFileType+'&hidDocType='+strDocType,
                    dataType: 'html',
                    async: false,
                    success: function(data){
    
                        strFileID = data
    
    
    
                    }
                }
            );
    
    
            jQuery('#pics').html ('<img src="/GYGlobal/images/icons/ajax-loader.gif"> Uploading Pic . . .');
                    jQuery.ajax({
                    type: "POST",
                    url: "/tools/document_picture_ajax.asp",
                    data: 'hidAjaxAction=PicUploadFile&hidFileID='+strFileID+'&hidObjFileData='+image+'&hidDocType='+strDocType,
                    dataType: 'html',
                    async: false,
                    success: function(data){
                        $("#preview").fadeOut("slow");
                        $("#info").fadeOut("slow");
                        AfterPicUpload ()
    
    
    
    
                    }
                }
            );
    
    
    
    
    }
    
    函数PicUpload(){
    var-strDocType;
    var-strImage;
    var-strPath;
    var strPicExtension;
    var-strDOTInfo;
    var-strFileType;
    strFileID变种;
    var图像;
    var imgsomething;
    strDocType=“”;
    strImage=($('img')[0].src);
    strPicExtension=strImage.substring(11,14)
    strDOTInfo=$(“#txtDotInformation”).val();
    strFileType=“”;
    strfleid=“”;
    image=“”;
    imgsomething=“”;
    if(strPicExtension==“jpe”){
    strFileType=“图像/jpeg”
    }
    如果(strPicExtension==“gif”){
    strFileType=“image/gif”
    }
    如果(strPicExtension==“png”){
    strFileType=“图像/png”
    }
    if(strPicExtension!=“jpe”){
    strPath=strImage.substring(22);
    }
    否则{
    strPath=strImage.substring(23);
    }
    如果(strDOTInfo==“”){
    警报(“您必须输入DOT信息”)
    $(“#txtDotInformation”).focus();
    返回false;
    }
    if(strDocType==“CALLUPLOAD”){
    var-strcalid;
    var-strDOTID;
    var-strDOTSizeCode;
    var-intDOTDateCode;
    strCallID=“”;
    strDOTID=strDOTInfo.substring(0,2);
    strDOTSizeCode=strDOTInfo.substring(2,4);
    intDOTDateCode=strDOTInfo.substring(4,8);
    如果(strCallID==“”){
    警报(“必须有呼叫ID”)
    返回false;
    }
    image=btoa(strPath);
    jQuery('#pics').html('Uploading Pic…');
    jQuery.ajax({
    类型:“POST”,
    url:“/tools/document\u picture\u ajax.asp”,
    数据:'hidAjaxAction=PicUpload&hidDOTID='+strDOTID+'&hidDOTSizeCode='+strDOTSizeCode+'&hidDOTDateCode='+intDOTDateCode+'&hidCallID='+strCallID+'&HIDDILETYPE='+strFileType+'&hidDocType='+strDocType+'+strDocType,
    数据类型:“html”,
    async:false,
    成功:功能(数据){
    strFileID=data
    }
    }
    );
    jQuery('#pics').html('Uploading Pic…');
    jQuery.ajax({
    类型:“POST”,
    url:“/tools/document\u picture\u ajax.asp”,
    数据:'hidAjaxAction=PicUploadFile&hidFileID='+strFileID+'&hidObjFileData='+image+'&hidDocType='+strDocType,
    数据类型:“html”,
    async:false,
    成功:功能(数据){
    $(“#预览”)。淡出(“缓慢”);
    $(“#信息”)。淡出(“缓慢”);
    上传后()
    }
    }
    );
    }
    
    现在,我的asp页面代码将所有内容放入数据库,以及我发现的用于解码base64字符串的函数

     Case "PicUpload":
    
    Select Case (strDocType)
     Case "CALLUPLOAD":
     Set objImagingFile = New clsImagingIndex
        With objImagingFile
    
            .intBatchID         = 0
            .strLocation        = gstrLocation
            .strDepartment      = "FleetHQ"
            .strDocumentType    = "Breakdown Photo"
            .strStatus          = "COMPLETE"
            .strKey1                = strCallID
            .strKey2                = strDOTID
            .strKey3                = strDOTSizeCode
            .strKey4                = intDOTDateCode
            .strFileName        = "Call Upload" & " " & strCallID
            .strFileType        = strFileType
            .strAddUser         = gstrUserID
            .strUpdUser         = gstrUserID
            .intFilePageNum = 1
            .Insert()
            intFileID           = .intFileID
            Response.Write intFileID
      End With
      Set objImagingFile = Nothing
      Case "DR":
        Set objImagingFile = New clsImagingIndex
        With objImagingFile
            .intBatchID         = 0
            .strLocation        = gstrLocation
            .strDepartment      = "Sales"
            .strDocumentType    = "Document Photo"
            .strStatus          = "COMPLETE"
            .strKey1                = strLocation
            .strKey2                = strDocType
            .strKey3                = strDocNumber
            .strKey4                = strDocVendor
            .strFileName        = strOriginalFileName
            .strFileType        = strFileType
            .strAddUser         = gstrUserID
            .strUpdUser         = gstrUserID
            .intFilePageNum = 1
            .Insert()
            intFileID           = .intFileID
        End With
        Set objImagingFile = Nothing
    Case "IN":
        Set objImagingFile = New clsImagingIndex
        With objImagingFile
            .intBatchID         = 0
             .strLocation       = gstrLocation
            .strDepartment      = "Sales"
            .strDocumentType    = "Document Photo"
            .strStatus          = "COMPLETE"
            .strKey1                = strLocation
            .strKey2                = strDocType
            .strKey3                = strDocNumber
            .strKey4                = strDocVendor
            .strFileName        = strOriginalFileName
            .strFileType        = strFileType
            .strAddUser         = gstrUserID
            .strUpdUser         = gstrUserID
            .intFilePageNum = 1
            .Insert()
            intFileID           = .intFileID
        End With
        Set objImagingFile = Nothing
     End Select
    
      Case "PicUploadFile":
       Dim objPicData
       Dim objPictureData
    
      'Response.Write strPath
    
     objPicData = Base64Decode(strPath)
    
     Response.Write objPicData
    
     objPictureData = Base64Decode(objPicData)
    
     Response.Write objPictureData
    
        Select Case (strDocType)
        Case "CALLUPLOAD":
    
        Set objImagingData = New clsImagingData
        With objImagingData
            .intFileID          = intFileID
            .dteDiskExpDate = "90" 'days to add to current date
            .dteDiskExpDate = DateAdd("d",30,Date())
            .objFileData        = objPictureData
            .Insert()
            'Call AddCallPictureCount
        End With
        Set objImagingData = Nothing
    
        Case "DR":
        Set objImagingData = New clsImagingData
        With objImagingData
            .intFileID          = intFileID
            .dteDiskExpDate = DateAdd("d",30,Date())
            .objFileData        = objFileData
            .Insert()
        Call AddDocumentPictureCount
        End With
        Set objImagingData = Nothing
        Case "IN":
        Set objImagingData = New clsImagingData
        With objImagingData
            .intFileID          = intFileID
            .dteDiskExpDate = "90" 'days to add to current date
            .dteDiskExpDate = DateAdd("d",30,Date())
            .objFileData        = objFileData
            .Insert()
         Call AddDocumentPictureCount
        End With
        Set objImagingData = Nothing
    End Select
    
       Function Base64Decode(ByVal strPath)
       'rfc1521
      '1999 Antonin Foller, Motobit Software, http://Motobit.cz
      Const Base64 =   "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
      Dim dataLength, sOut, groupBegin
    
    
    
     'remove white spaces, If any
     strPath = Replace(strPath, vbCrLf, "")
     strPath = Replace(strPath, vbTab, "")
      strPath = Replace(strPath, " ", "")
    
      'The source must consists from groups with Len of 4 chars
      dataLength = Len(strPath)
      If dataLength Mod 4 <> 0 Then
       Err.Raise 1, "Base64Decode", "Bad Base64 string."
       Exit Function
     End If
    
    
      ' Now decode each group:
      For groupBegin = 1 To dataLength Step 4
       Dim numDataBytes, CharCounter, thisChar, thisData, nGroup, pOut
       ' Each data group encodes up To 3 actual bytes.
       numDataBytes = 3
        nGroup = 0
    
       For CharCounter = 0 To 3
      ' Convert each character into 6 bits of data, And add it To
      ' an integer For temporary storage.  If a character is a '=', there
      ' is one fewer data byte.  (There can only be a maximum of 2 '=' In
      ' the whole string.)
    
      thisChar = Mid(strPath, groupBegin + CharCounter, 1)
    
      If thisChar = "=" Then
        numDataBytes = numDataBytes - 1
        thisData = 0
      Else
        thisData = InStr(1, Base64, thisChar, vbBinaryCompare) - 1
      End If
      If thisData = -1 Then
        Err.Raise 2, "Base64Decode", "Bad character In Base64 string."
        Exit Function
      End If
    
      nGroup = 64 * nGroup + thisData
       Next
    
    'Hex splits the long To 6 groups with 4 bits
    nGroup = Hex(nGroup)
    
    
    'Add leading zeros
    nGroup = String(6 - Len(nGroup), "0") & nGroup
    
    'Convert the 3 byte hex integer (6 chars) To 3 characters
    pOut = Chr(CByte("&H" & Mid(nGroup, 1, 2))) + _
      Chr(CByte("&H" & Mid(nGroup, 3, 2))) + _
      Chr(CByte("&H" & Mid(nGroup, 5, 2)))
    
    'add numDataBytes characters To out string
    sOut = sOut & Left(pOut, numDataBytes)
      Next
    
      Base64Decode = sOut
    End Function
    
       Function Base64Decode(ByVal objPicData)
      'rfc1521
      '1999 Antonin Foller, Motobit Software, http://Motobit.cz
     Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
      Dim dataLength, sOut, groupBegin
    
    
    
     'remove white spaces, If any
     objPicData = Replace(objPicData, vbCrLf, "")
     objPicData = Replace(objPicData, vbTab, "")
      objPicData = Replace(objPicData, " ", "")
    
    'The source must consists from groups with Len of 4 chars
    dataLength = Len(objPicData)
     If dataLength Mod 4 <> 0 Then
      Err.Raise 1, "Base64Decode", "Bad Base64 string."
      Exit Function
      End If
    
    
     ' Now decode each group:
      For groupBegin = 1 To dataLength Step 4
      Dim numDataBytes, CharCounter, thisChar, thisData, nGroup, pOut
       ' Each data group encodes up To 3 actual bytes.
       numDataBytes = 3
       nGroup = 0
    
       For CharCounter = 0 To 3
      ' Convert each character into 6 bits of data, And add it To
      ' an integer For temporary storage.  If a character is a '=', there
      ' is one fewer data byte.  (There can only be a maximum of 2 '=' In
      ' the whole string.)
    
        thisChar = Mid(objPicData, groupBegin + CharCounter, 1)
    
        If thisChar = "=" Then
        numDataBytes = numDataBytes - 1
        thisData = 0
      Else
        thisData = InStr(1, Base64, thisChar, vbBinaryCompare) - 1
      End If
      If thisData = -1 Then
        Err.Raise 2, "Base64Decode", "Bad character In Base64 string."
        Exit Function
      End If
    
      nGroup = 64 * nGroup + thisData
       Next
    
    'Hex splits the long To 6 groups with 4 bits
    nGroup = Hex(nGroup)
    
    'Add leading zeros
    nGroup = String(6 - Len(nGroup), "0") & nGroup
    
    'Convert the 3 byte hex integer (6 chars) To 3 characters
    pOut = Chr(CByte("&H" & Mid(nGroup, 1, 2))) + _
      Chr(CByte("&H" & Mid(nGroup, 3, 2))) + _
      Chr(CByte("&H" & Mid(nGroup, 5, 2)))
    
    'add numDataBytes characters To out string
    sOut = sOut & Left(pOut, numDataBytes)
      Next
    
    Base64Decode = sOut
    End Function
    
    案例“PicUpload”:
    选择案例(strDocType)
    案例“CALLUPLOAD”:
    设置objImagingFile=New clsImagingIndex
    使用objImagingFile
    .intBatchID=0
    .strLocation=gstrLocation
    .strDepartment=“FleetHQ”
    .strDocumentType=“分解照片”
    .strStatus=“完成”
    .strKey1=strCallID
    .strKey2=strDOTID
    .strKey3=strDOTSizeCode
    .strKey4=intDOTDateCode
    .strFileName=“调用上载”和“&strCallID”
    .strFileType=strFileType
    .strAddUser=gstrUserID
    .strUpdUser=gstrUserID
    .intFilePageNum=1
    .插入()
    intFileID=.intFileID
    Response.Write intFileID
    以
    设置objImagingFile=Nothing
    案例“DR”:
    设置objImagingFile=New clsImagingIndex
    使用objImagingFile
    .intBatchID=0
    .strLocation=gstrLocation
    .strDepartment=“销售”
    .strDocumentType=“文档照片”
    .strStatus=“完成”
    .strKey1=strLocation
    strKey2先生
    
     Case "PicUpload":
    
    Select Case (strDocType)
     Case "CALLUPLOAD":
     Set objImagingFile = New clsImagingIndex
        With objImagingFile
    
            .intBatchID         = 0
            .strLocation        = gstrLocation
            .strDepartment      = "FleetHQ"
            .strDocumentType    = "Breakdown Photo"
            .strStatus          = "COMPLETE"
            .strKey1                = strCallID
            .strKey2                = strDOTID
            .strKey3                = strDOTSizeCode
            .strKey4                = intDOTDateCode
            .strFileName        = "Call Upload" & " " & strCallID
            .strFileType        = strFileType
            .strAddUser         = gstrUserID
            .strUpdUser         = gstrUserID
            .intFilePageNum = 1
            .Insert()
            intFileID           = .intFileID
            Response.Write intFileID
      End With
      Set objImagingFile = Nothing
      Case "DR":
        Set objImagingFile = New clsImagingIndex
        With objImagingFile
            .intBatchID         = 0
            .strLocation        = gstrLocation
            .strDepartment      = "Sales"
            .strDocumentType    = "Document Photo"
            .strStatus          = "COMPLETE"
            .strKey1                = strLocation
            .strKey2                = strDocType
            .strKey3                = strDocNumber
            .strKey4                = strDocVendor
            .strFileName        = strOriginalFileName
            .strFileType        = strFileType
            .strAddUser         = gstrUserID
            .strUpdUser         = gstrUserID
            .intFilePageNum = 1
            .Insert()
            intFileID           = .intFileID
        End With
        Set objImagingFile = Nothing
    Case "IN":
        Set objImagingFile = New clsImagingIndex
        With objImagingFile
            .intBatchID         = 0
             .strLocation       = gstrLocation
            .strDepartment      = "Sales"
            .strDocumentType    = "Document Photo"
            .strStatus          = "COMPLETE"
            .strKey1                = strLocation
            .strKey2                = strDocType
            .strKey3                = strDocNumber
            .strKey4                = strDocVendor
            .strFileName        = strOriginalFileName
            .strFileType        = strFileType
            .strAddUser         = gstrUserID
            .strUpdUser         = gstrUserID
            .intFilePageNum = 1
            .Insert()
            intFileID           = .intFileID
        End With
        Set objImagingFile = Nothing
     End Select
    
      Case "PicUploadFile":
       Dim objPicData
       Dim objPictureData
    
      'Response.Write strPath
    
     objPicData = Base64Decode(strPath)
    
     Response.Write objPicData
    
     objPictureData = Base64Decode(objPicData)
    
     Response.Write objPictureData
    
        Select Case (strDocType)
        Case "CALLUPLOAD":
    
        Set objImagingData = New clsImagingData
        With objImagingData
            .intFileID          = intFileID
            .dteDiskExpDate = "90" 'days to add to current date
            .dteDiskExpDate = DateAdd("d",30,Date())
            .objFileData        = objPictureData
            .Insert()
            'Call AddCallPictureCount
        End With
        Set objImagingData = Nothing
    
        Case "DR":
        Set objImagingData = New clsImagingData
        With objImagingData
            .intFileID          = intFileID
            .dteDiskExpDate = DateAdd("d",30,Date())
            .objFileData        = objFileData
            .Insert()
        Call AddDocumentPictureCount
        End With
        Set objImagingData = Nothing
        Case "IN":
        Set objImagingData = New clsImagingData
        With objImagingData
            .intFileID          = intFileID
            .dteDiskExpDate = "90" 'days to add to current date
            .dteDiskExpDate = DateAdd("d",30,Date())
            .objFileData        = objFileData
            .Insert()
         Call AddDocumentPictureCount
        End With
        Set objImagingData = Nothing
    End Select
    
       Function Base64Decode(ByVal strPath)
       'rfc1521
      '1999 Antonin Foller, Motobit Software, http://Motobit.cz
      Const Base64 =   "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
      Dim dataLength, sOut, groupBegin
    
    
    
     'remove white spaces, If any
     strPath = Replace(strPath, vbCrLf, "")
     strPath = Replace(strPath, vbTab, "")
      strPath = Replace(strPath, " ", "")
    
      'The source must consists from groups with Len of 4 chars
      dataLength = Len(strPath)
      If dataLength Mod 4 <> 0 Then
       Err.Raise 1, "Base64Decode", "Bad Base64 string."
       Exit Function
     End If
    
    
      ' Now decode each group:
      For groupBegin = 1 To dataLength Step 4
       Dim numDataBytes, CharCounter, thisChar, thisData, nGroup, pOut
       ' Each data group encodes up To 3 actual bytes.
       numDataBytes = 3
        nGroup = 0
    
       For CharCounter = 0 To 3
      ' Convert each character into 6 bits of data, And add it To
      ' an integer For temporary storage.  If a character is a '=', there
      ' is one fewer data byte.  (There can only be a maximum of 2 '=' In
      ' the whole string.)
    
      thisChar = Mid(strPath, groupBegin + CharCounter, 1)
    
      If thisChar = "=" Then
        numDataBytes = numDataBytes - 1
        thisData = 0
      Else
        thisData = InStr(1, Base64, thisChar, vbBinaryCompare) - 1
      End If
      If thisData = -1 Then
        Err.Raise 2, "Base64Decode", "Bad character In Base64 string."
        Exit Function
      End If
    
      nGroup = 64 * nGroup + thisData
       Next
    
    'Hex splits the long To 6 groups with 4 bits
    nGroup = Hex(nGroup)
    
    
    'Add leading zeros
    nGroup = String(6 - Len(nGroup), "0") & nGroup
    
    'Convert the 3 byte hex integer (6 chars) To 3 characters
    pOut = Chr(CByte("&H" & Mid(nGroup, 1, 2))) + _
      Chr(CByte("&H" & Mid(nGroup, 3, 2))) + _
      Chr(CByte("&H" & Mid(nGroup, 5, 2)))
    
    'add numDataBytes characters To out string
    sOut = sOut & Left(pOut, numDataBytes)
      Next
    
      Base64Decode = sOut
    End Function
    
       Function Base64Decode(ByVal objPicData)
      'rfc1521
      '1999 Antonin Foller, Motobit Software, http://Motobit.cz
     Const Base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
      Dim dataLength, sOut, groupBegin
    
    
    
     'remove white spaces, If any
     objPicData = Replace(objPicData, vbCrLf, "")
     objPicData = Replace(objPicData, vbTab, "")
      objPicData = Replace(objPicData, " ", "")
    
    'The source must consists from groups with Len of 4 chars
    dataLength = Len(objPicData)
     If dataLength Mod 4 <> 0 Then
      Err.Raise 1, "Base64Decode", "Bad Base64 string."
      Exit Function
      End If
    
    
     ' Now decode each group:
      For groupBegin = 1 To dataLength Step 4
      Dim numDataBytes, CharCounter, thisChar, thisData, nGroup, pOut
       ' Each data group encodes up To 3 actual bytes.
       numDataBytes = 3
       nGroup = 0
    
       For CharCounter = 0 To 3
      ' Convert each character into 6 bits of data, And add it To
      ' an integer For temporary storage.  If a character is a '=', there
      ' is one fewer data byte.  (There can only be a maximum of 2 '=' In
      ' the whole string.)
    
        thisChar = Mid(objPicData, groupBegin + CharCounter, 1)
    
        If thisChar = "=" Then
        numDataBytes = numDataBytes - 1
        thisData = 0
      Else
        thisData = InStr(1, Base64, thisChar, vbBinaryCompare) - 1
      End If
      If thisData = -1 Then
        Err.Raise 2, "Base64Decode", "Bad character In Base64 string."
        Exit Function
      End If
    
      nGroup = 64 * nGroup + thisData
       Next
    
    'Hex splits the long To 6 groups with 4 bits
    nGroup = Hex(nGroup)
    
    'Add leading zeros
    nGroup = String(6 - Len(nGroup), "0") & nGroup
    
    'Convert the 3 byte hex integer (6 chars) To 3 characters
    pOut = Chr(CByte("&H" & Mid(nGroup, 1, 2))) + _
      Chr(CByte("&H" & Mid(nGroup, 3, 2))) + _
      Chr(CByte("&H" & Mid(nGroup, 5, 2)))
    
    'add numDataBytes characters To out string
    sOut = sOut & Left(pOut, numDataBytes)
      Next
    
    Base64Decode = sOut
    End Function