简体   繁体   English

Java Spring WebFlux 多部分文件上传

[英]Java Spring WebFlux Multipart File Upload

I am trying to make simple post-request with a image.我正在尝试使用图像进行简单的后期请求。 But it is not working.但它不起作用。

My html post form data (multipart/form-data):我的 html 发布表单数据(多部分/表单数据):

book[0].cover = 123.jpg;  <--- upload file image
book[0].title = "title 123";
book[0].author = "123"

book[1].cover = abc.jpg;
book[1].title = "title abc";
book[1].author = "abc"

restapi image restapi 图像

curl -X POST http://127.0.0.1/book/postCreate \
    -H 'Content-Type: multipart/form-data' \
    -d 'book%5B0%5D.file=[$file.30378169-jpg]&book%5B0%5D.title=title%20123&book%5B0%5D.author=author%20123&book%5B1%5D.file=[$file.30378190-jpg]&book%5B1%5D.title=title%20abc&book%5B0%5D.author=author%20abc'

My controller method is setup as follows:我的 controller 方法设置如下:

public Mono<ServerResponse> postCreate(ServerRequest request) {
    Flux<Book> book = request.bodyToFlux(Book.class);  // error
    // How can I get the data of the form ?
}

class Book {
    FilePart cover;
    String title;
    String author;
}

How can I get the data of the form?如何获取表单的数据?

Im not the best at java, but when I go into visual studio code and enter this in, it gives me a couple of errors.我在 java 方面不是最好的,但是当我将 go 输入到 Visual Studio 代码中并将其输入时,它给了我一些错误。

book[0].cover = 123.jpg;  <--- uplaod file image
book[0].title = "title 123";
book[0].author = "123"

book[1].cover = abc.jpg;
book[1].title = "title abc";
book[1].author = "abc"

first of all, upload is spelt wrong, that's probably why.首先,upload 拼写错误,这可能就是原因。 When I click on the word "file" in visual studio code it will just change to "File" not "file".当我在 Visual Studio 代码中单击“文件”一词时,它只会更改为“文件”而不是“文件”。 I think capitalization is the problem here but I'm not fluent in java.我认为大写是这里的问题,但我不熟悉 java。

Like I said, I'm not fluent in java because I code python and sometimes JavaScript but I have never seen a error like this.就像我说的那样,我对 java 不流利,因为我编码 python 有时是 JavaScript 但我从未见过这样的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM