【问题标题】:Kendo.Upload. Upload method doesn't fire onUpload event剑道。上传。上传方法不会触发 onUpload 事件
【发布时间】:2019-02-03 11:03:16
【问题描述】:

当 Kendo Upload 组件应该执行第二次上传时,不会触发 onUpload 事件处理程序。

我使用带有cropperjs(https://github.com/fengyuanchen/cropperjs/blob/master/README.md)的剑道上传来上传图像,裁剪它然后发送到服务器。如果图像太大,服务器会发送错误。期望用户选择另一个裁剪区域并再次发送图像。在最后一步没有任何反应。

这里是裁剪图像并触发上传的方法

        cropper.crop();
        var canvas = cropper.getCroppedCanvas();

        canvas.toBlob(function (blob) {
            image = blob;
            $("#file").data("kendoUpload").upload();
        });

然后在 onUpload 处理程序中,初始裁剪后的图像被裁剪后的图像替换。

    e.data = {
        file: image,
        userName: $("#User_Login").val()
    };

在服务器上给我发送一个错误:

public virtual ActionResult UpdateUserImage([FromBody]HttpPostedFileBase file, [FromBody]string userName)
        {
            try
            {
                ImageHelper.CheckImage(file);
            }
            catch (Exception e)
            {
                return new LargeJsonResult(new
                {
                    error = e.Message,
                })
                {
                    StatusCode = HttpStatusCode.PreconditionFailed
                };
            }
           ...
        }

错误在onError进程处理程序中处理:

        var err = e.XMLHttpRequest;
        if (err.status === 412) {
            var body = JSON.parse(err.response);
            alert(body.error);
        }
        else {
            alert("Unable to upload the file. Please check that the 
                        size is less than 10Mb.");
        }   

之后,允许用户裁剪已选择的图像。并且在更改裁剪区域后,预计将重复上述步骤。但是在第一个代码块中的$("#file").data("kendoUpload").upload(); 之后没有任何反应。但是,我希望必须调用 onUpload 事件处理程序。

【问题讨论】:

    标签: javascript asp.net-mvc kendo-asp.net-mvc kendo-upload cropper


    【解决方案1】:

    我找到了解决方案 :) 我没有将图像发送到服务器并在那里检查大小,而是在客户端检查大小并在需要时阻止发送。 我的意思是在打电话给$("#file").data("kendoUpload").upload();之前我打电话给

               if (image.size > 10 * 1024 * 1024) {
                    alert("File is too big!");
                    return;
                }
    

    一切正常。 但是,如果有人仍然知道为什么 $("#file").data("kendoUpload").upload(); 不触发 onUpload 事件处理程序,那么与我分享想法会很棒:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多