【问题标题】:kendo-angular-upload: Error event not fired after a 500 Server Error Codekendo-angular-upload:500 服务器错误代码后未触发错误事件
【发布时间】:2019-05-30 11:01:29
【问题描述】:

在前端我使用 Angular 7 并尝试使用 Kendo 上传图像:

        <kendo-upload
          [saveUrl]="uploadSaveUrl"
          [removeUrl]="uploadRemoveUrl"
          [restrictions]="uploadRestrictions"
          [multiple]="false"
          [withCredentials]="false"
          (success)="showSavedSuccess()"
          (error)=showSavedFailed($event)
        >

在后端我使用 ASP.NET Core。我基本上使用从这里获取的代码(常规控制器类型版本): https://www.telerik.com/forums/file-upload-full-example-with-server-side-code

当我尝试时,成功事件被触发。但是,如果我想测试错误,而不是

return Ok(new { count = files.Count, size, filePath });

我用

return StatusCode(500);

在这种情况下,(error) event 不会被触发,我仍然会收到来自 Kendo 的消息 Uploading...。如果我检查网络,我会清楚地看到 500 error 消息。

我尝试从后端发送不同的响应(null,...),但我得到的结果都相同。

顺便说一下,这个问题与标题相似的this one无关。

我应该解决什么问题?我应该从 BE 返回某个错误值,还是必须以不同的方式处理 Kendo 的模块?我在 Kendo 的页面中没有找到此信息...求助!

【问题讨论】:

    标签: angular kendo-ui


    【解决方案1】:

    error event 在上传或删除操作失败时触发。 This is an example.

    状态码 500 永远不应到达客户端。 Such exceptions should be handled on the server side。应从服务器返回正确的 HTTP 状态代码/错误。

    These 是此处最常见状态码的内置 ASP.NET Core 方法,用于触发上传组件的错误事件。或者,Angular Interceptor 可用于自定义整个客户端-服务器通信。可以从自定义拦截器组件发送自定义错误响应。 Example.

    来源:Telerik 支持团队。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-29
      • 1970-01-01
      • 2017-09-03
      • 1970-01-01
      • 1970-01-01
      • 2020-03-24
      • 1970-01-01
      相关资源
      最近更新 更多