2

我想使用Ajax-Upload脚本来上传多张图片。最重要的是我必须使用 Asp.net webforms,我一直在做 ajax 的方式是有一个像这样的简单页面 web 方法。

[WebMethod()]
public static string Method(string param)
{
    return "Hello World";
}

我在弄清楚如何在不使用 webforms FileUpload 控件的情况下上传图像时遇到了麻烦,因此我可以异步上传文件。我一定是使用了错误的搜索词,因为我在网络表单中找不到另一个这样做的人的例子。

编辑:更具体地说,我正在寻求服务器端的帮助。我链接到的插件处理所有客户端的东西。我目前正在考虑编写一个客户处理程序......

我宁愿避免使用更新面板控件(如 AjaxToolkit),如果可能的话就坚持使用插件。

4

2 回答 2

1

在 asp.net-ajax 中,您可以 Asyncupload,它是 Ajax 控制工具包的一部分。 http://www.asp.net/ajax/ajaxcontroltoolkit/samples/AsyncFileUpload/AsyncFileUpload.aspx 如果您正在查看 jquery 插件,请查看 uploadify http://www.uploadify.com

于 2011-06-06T18:05:45.180 回答
0

回答:

我所做的是编写了一个非常基本的图像上传处理程序脚本,但它应该可以完成工作。这里是。

    public void ProcessRequest(HttpContext context)
    {
        string uploadDir = "C:\\Upload";
        try
        {
            Image i = Image.FromStream(context.Request.InputStream);
            string filename = context.Request.Params["qqfile"];

            if (i.RawFormat.Equals(ImageFormat.Png))
            {
                i.Save(uploadDir + "\\" + filename, ImageFormat.Png);
            }
            else if (i.RawFormat.Equals(ImageFormat.Jpeg))
            {
                i.Save(uploadDir + "\\" + filename, ImageFormat.Jpeg);
            }
            else if (i.RawFormat.Equals(ImageFormat.Gif))
            {
                i.Save(uploadDir + "\\" + filename, ImageFormat.Gif);
            }
            else if (i.RawFormat.Equals(ImageFormat.Bmp))
            {
                i.Save(uploadDir + "\\" + filename, ImageFormat.Bmp);
            }
        }
        catch (Exception e)
        {
            context.Response.Write("{'error':'"+e.Message+"'}");
        }

        context.Response.Write("{'success':true}");
    }

这适用于我之前链接到的 Ajax-Upload 脚本。谢谢

于 2011-06-15T19:56:09.730 回答