You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular图片保存接口返回404问题排查:误用API端点

图片保存接口404问题解决记录

问题现象

  • 初始阶段:编写的图片保存方法中,console.log可正常打印this.educationalData数据,但尝试从接口获取id时返回undefined。
  • 调整后:请求已能携带id为1的参数发送,但接口返回404状态码。

涉及代码

Angular前端代码

saveImage() {
  const file = this.imageChangedEvent;
  const reader = new FileReader();
  reader.readAsDataURL(file);
  reader.onload = () =>{
    this.apiService.postData('educational-award/' + this.educationalData[0].id, {
      "photo": reader.result,
      "id": this.educationalData[0].id
    }).subscribe(data =>{
      console.log('test')
    });
  };
}

正确的后端路由(Laravel)

Route::post('/upload-picture', [UserController::class, 'uploadPicture']);

问题根源

之前请求使用了错误的API端点,导致接口返回404,修正为上述正确路由即可解决。

补充说明截图

接口路由配置截图

内容的提问来源于stack exchange,提问作者Kael

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 10:06:20