如何从AjaxFileUpload获取base64镜像?

时间:2014-10-10 19:00:27

标签: c# jquery asp.net ajax ajaxcontroltoolkit

我正在尝试将图像作为base64字符串放入AjaxFileUpload中。我会在OnUploadCompleteAll中执行此操作吗?

    protected void AjaxFileUpload1_UploadCompleteAll(object sender, AjaxFileUploadCompleteAllEventArgs e)
    {

    }

在aspx中:

<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" AllowedFileTypes="jpg,jpeg,png,gif" MaximumNumberOfFiles="5" OnUploadCompleteAll="AjaxFileUpload1_UploadCompleteAll"></asp:AjaxFileUpload>

1 个答案:

答案 0 :(得分:0)

当所有文件(在多重上传中)完成时,UploadCompleteAll事件将触发。

还有一个事件会为每个上传的文件触发一次,称为UploadComplete。你应该处理那件事。

// in ASPX page
<asp:AjaxFileUpload ID="AjaxFileUpload1" 
                    runat="server"
                    AllowedFileTypes="jpg,jpeg,png,gif"
                    MaximumNumberOfFiles="5"
                    OnUploadCompleteAll="AjaxFileUpload1_UploadCompleteAll"
                    OnUploadComplete="AjaxFileUpload1_UploadComplete">
</asp:AjaxFileUpload>

在后面的代码中添加如下内容:

// in code-behind
protected void AjaxFileUpload1__OnUploadComplete(object sender, AjaxFileUploadEventArgs e)
{       
    if (e.ContentType.Contains("jpg") || file.ContentType.Contains("jpeg")
            || file.ContentType.Contains("png") || file.ContentType.Contains("gif"))
    {           
        // file.FileName contains the name of the file
        fileUploader.SaveAs(MapPath("path/where/you/want/to/save/file"));

        // once saved, you can further manipulate the file if you wish

    }
}