我正在尝试实现我在网上找到的一段代码,以便在html5画布上上传一些图纸,以便我可以将图像附加到电子邮件中 .

<script type="text/javascript">
    // Send the canvas image to the server.
        $(document).ready(function () {
        $('#btnSave').live('click', function () {

            var image = document.getElementById("tools_sketch").toDataURL();
            image = image.replace('data:image/png;base64,', '');
            $.ajax({
                type: 'POST',
                url: 'upload.aspx/UploadImage',
                data: '{ "imageData" : "' + image + '" }',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (msg) {
                    alert('Image sent!');
                }, 
                error: function (msg2) {
                    alert('Image problem!' + msg2.toString());
                 }

            });
         });

     });


        </script>

upload.aspx

<%@ Page Language="VB" AutoEventWireup="true" CodeFile="upload.aspx.vb" Inherits="CanvasToServer._upload" %>

upload.aspx.vb

Imports System.IO命名空间CanvasToServer Partial Class _upload Inherits System.Web.UI.Page Public Shared Sub UploadImage(ByVal imageData As String)

Dim fs As New FileStream("C:\uploaded\image.png", FileMode.Create)
        Dim bw As New BinaryWriter(fs)
        Dim data As Byte() = Convert.FromBase64String(imageData)

        bw.Write(data)
        bw.Close()
    End Sub
End Class

结束命名空间

该行导致编译错误“属性说明符不是完整的语句 . 使用行继续将该属性应用于以下语句 . ”如果我删除该行代码编译但画布图像仍然没有上传到服务器 . 我在localhost上运行此代码,并且我的机器上存在文件夹c:\ uploaded .