当Kendo Upload组件第二次执行upload时,onUpload事件处理程序不会触发。
我使用kendo upload with the 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事件处理程序。
发布于 2019-02-04 10:57:34
我找到了解决方案:)不是将图像发送到服务器并在那里检查大小,而是检查客户端的大小,并在需要时阻止发送。我是说在给$("#file").data("kendoUpload").upload();打电话之前我会先
if (image.size > 10 * 1024 * 1024) {
alert("File is too big!");
return;
}一切都很好。但是,如果有人仍然知道$("#file").data("kendoUpload").upload();为什么不触发onUpload事件处理程序,那么与我分享一下想法就太好了:)
https://stackoverflow.com/questions/54502171
复制相似问题