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. 解决了问题

相关推荐
阿部多瑞 ABU1 小时前
# 从底层架构到应用实践:为何部分大模型在越狱攻击下失守?
gpt·安全·ai·自然语言处理
市象2 小时前
联想困局,破于AI?
人工智能·ai·联想
hstar95273 小时前
三十三、面向对象底层逻辑-SpringMVC九大组件之HandlerExceptionResolver接口设计
java·spring·设计模式·架构
面朝大海,春不暖,花不开3 小时前
Spring Security默认配置覆盖指南
java·后端·spring
IT_Octopus5 小时前
多线程下使用缓存+锁Lock, 出现“锁失效” + “缓存未命中竞争”的缓存击穿情况,双重检查缓存解决问题
java·spring·缓存
阿部多瑞 ABU5 小时前
大模型安全测试报告:千问、GPT 全系列、豆包、Claude 表现优异,DeepSeek、Grok-3 与 Kimi 存在安全隐患
gpt·安全·ai
qq_3380329210 小时前
Spring Boot/Spring应用中配置自定义RedisTemplate
spring boot·redis·spring
考虑考虑10 小时前
Springboot3.5.x版本actuator新属性
spring boot·后端·spring
Juicedata14 小时前
JuiceFS v1.3-Beta2:集成 Apache Ranger,实现更精细化的权限控制
运维·人工智能·ai
萌新小码农‍20 小时前
Spring框架学习day7--SpringWeb学习(概念与搭建配置)
学习·spring·状态模式