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

相关推荐
信息安全失业大专人员14 小时前
每日了解一个智能体-WorkBuddy
开发语言·ai·c#·智能体
OpenAnolis小助手14 小时前
龙蜥社区亮相 GOSIM AI Vision Forum 共话“Agentic Native”开源新
人工智能·ai·开源·操作系统·龙蜥社区·agent
恩喜玛生物14 小时前
03_GROMACS分子动力学实战:从 Factor Xa 输入准备到轨迹分析
ai
gz927cool15 小时前
Python 全栈应用最佳实践完整指南
开发语言·python·ai
CoderYanger16 小时前
Java EE 进阶:5. Spring IoC&DI(第三弹):Spring DI
java·开发语言·spring boot·spring·面试·java-ee·mvc
郭小李16 小时前
spring中@Transactional注解对事务的支持
数据库·spring·oracle
日日大王学编程17 小时前
阿里巴巴开源 Data Agent(Text2SQL)项目全维度详解
java·ai·开源
七夜zippoe17 小时前
Agent 测试实战:单元测试、集成测试与 Mock LLM 策略
ai·单元测试·集成测试·mock·agent
Solange__18 小时前
物流园区怎么用AI生成3D调度预演?从道路底图、车辆转弯到网页评审
图像处理·人工智能·游戏·3d·ai·自然语言处理·关卡设计
最强小杰18 小时前
gpt-image-2.5-sunburst + OpenAI SDK + Cline 怎么接?完整图生图与局部重绘教程
gpt·ios·ai·iphone