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

相关推荐
代码小鑫2 小时前
A043-基于Spring Boot的秒杀系统设计与实现
java·开发语言·数据库·spring boot·后端·spring·毕业设计
真心喜欢你吖2 小时前
SpringBoot与MongoDB深度整合及应用案例
java·spring boot·后端·mongodb·spring
老艾的AI世界3 小时前
AI翻唱神器,一键用你喜欢的歌手翻唱他人的曲目(附下载链接)
人工智能·深度学习·神经网络·机器学习·ai·ai翻唱·ai唱歌·ai歌曲
斗-匕4 小时前
Spring事务管理
数据库·spring·oracle
Doker 多克7 小时前
Spring AI 框架使用的核心概念
人工智能·spring·chatgpt
请叫我青哥10 小时前
第五十二条:谨慎使用重载
java·spring
孟秋与你11 小时前
【spring】spring单例模式与锁对象作用域的分析
java·spring·单例模式
luckywuxn12 小时前
Spring Cloud Alibaba、Spring Cloud 与 Spring Boot各版本的对应关系
spring boot·spring·spring cloud
是程序喵呀12 小时前
SpringMVC详解
java·spring·spring-mvc
飞起来fly呀12 小时前
AI驱动电商新未来:提升销售效率与用户体验的创新实践
人工智能·ai