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

相关推荐
计算机学姐6 小时前
基于微信小程序的驾校预约小程序
java·vue.js·spring boot·后端·spring·微信小程序·小程序
qw94910 小时前
Spring 6 第6章——单元测试:Junit
spring·junit·单元测试
荆州克莱11 小时前
Golang的网络编程安全
spring boot·spring·spring cloud·css3·技术
清风-云烟12 小时前
使用redis-cli命令实现redis crud操作
java·linux·数据库·redis·spring·缓存·1024程序员节
AI2AGI12 小时前
天天AI-20250121:全面解读 AI 实践课程:动手学大模型(含PDF课件)
大数据·人工智能·百度·ai·文心一言
好像是个likun12 小时前
spring Ioc 容器的简介和Bean之间的关系
java·后端·spring
拾忆,想起12 小时前
微服务入门:从零开始构建你的微服务架构
spring·spring cloud·微服务·架构
鸭鸭鸭进京赶烤15 小时前
OpenAI秘密重塑机器人军团: 实体AGI的崛起!
人工智能·opencv·机器学习·ai·机器人·agi·机器翻译引擎
佛州小李哥18 小时前
在亚马逊云科技上用AI提示词优化功能写出漂亮提示词(下)
人工智能·科技·ai·语言模型·云计算·aws·亚马逊云科技
mqiqe18 小时前
Spring AI TikaDocumentReader
人工智能·spring·知识图谱