Fileupload - Endpoint and OpenAI Generation for the Service

题意:文件上传 - 服务的端点和OpenAI生成

问题背景:

My Endpoint is a RestConroller with a Post-Method looking like this:

我的端点是一个带有 Post 方法的 RestController,如下所示

java 复制代码
@PostMapping(path = "/xetra", consumes =  {
    MediaType.APPLICATION_JSON_VALUE,
    MediaType.MULTIPART_FORM_DATA_VALUE})

public @ResponseBody void importXetra(@RequestParam("file") MultipartFile file) {

After OpenAI Generator i get the following signature for the endpoint:

使用 OpenAI 生成器后,我得到的端点签名如下

java 复制代码
public importXetra(importXetraRequest?: ImportXetraRequest, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext}): Observable<any>;
public importXetra(importXetraRequest?: ImportXetraRequest, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext}): Observable<HttpResponse<any>>;
public importXetra(importXetraRequest?: ImportXetraRequest, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: undefined, context?: HttpContext}): Observable<HttpEvent<any>>;
public importXetra(importXetraRequest?: ImportXetraRequest, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: undefined, context?: HttpContext}): Observable<any> {

with

java 复制代码
export interface ImportXetraRequest { 
file: Blob;
}

My formular looks like: 我的表单如下:

XML 复制代码
<p-fileUpload name="myfile[]" [customUpload]="true" (uploadHandler)="upload($event)">
<ng-template pTemplate="toolbar">
  <div class="py-1">Upload 1 Files</div>
</ng-template>
<ng-template let-file pTemplate="file">
  <div>Custom UI to display a file</div>
</ng-template>

my upload implementation: 我的上传实现

javascript 复制代码
upload (event : {files: Blob[]}) : void {
let file  = event.files[0] as File;
let request: ImportXetraRequest = ({} as any) as ImportXetraRequest;
request.file = file;
this.importEndpoint.importXetra(request).subscribe({
  next : (res : void) => console.log("imported"),
  error: (e: ErrorEvent) => console.error("error = " + e),
});
}

I don't know how exactly i can do the call to the backend, the backend says it is not a valid request. I get a 500-error. It also seems that the payload is not set/empty.

我不确定如何正确地调用后端,后端提示请求无效。我收到一个500错误。似乎负载没有设置或为空

问题解决:

The problem was, that the endpoint didn't have the correct MediaType Consumer:

问题在于,该端点没有正确的MediaType Consumer

javascript 复制代码
@PostMapping(path = "/xetra", consumes =  {
        MediaType.MULTIPART_FORM_DATA_VALUE,
})

solved the problem. 解决了问题

相关推荐
thesky1234568 小时前
27届大模型岗面试准备(十三):长上下文与上下文工程——从位置外推到分块策略的完整考点
人工智能·ai·大模型
Husp070711 小时前
Prompt入门到精通系列(一)
ai·语言模型
Summer-Bright12 小时前
AI 软件简报 07.29-08.02:OpenAI 降价 80%、DeepSeek 全开源、欧盟动刀
人工智能·ai·开源·ai软件
熏鱼的小迷弟Liu12 小时前
【AI】Loop Engineering 的演进
ai
不吃紫菜13 小时前
别光会用 Skill,不会写等于白搭:从规范到原理,手把手教你给 AI Agent 造技能
ai
码农小韩14 小时前
AIAgent应用开发——大模型理论基础与应用(七)
python·学习·ai·大模型·agent
不才不才不不才14 小时前
Spring 源码系列(14): JDK 动态代理 vs CGLIB,以及拦截器责任链
java·开发语言·spring
晨曦中的暮雨14 小时前
Learn Claude Code:CodeAgent 的状态机流程编排——Todo任务系统和自主智能体
ai·大模型·agent
用户31268748772014 小时前
Spring 事件机制到底怎么传播的?ApplicationEvent 源码拆解
java·spring
2501_9339232515 小时前
设计网页的时候加载不出来怎么办?认识常见的状态码
前端·spring