如何使用jodd-http上传多个文件?
How to upload multiple files with jodd-http?
如何使用 jodd HTTP 在同一请求中上传多个文件?
我试过类似下面的方法,但只发布了第一个文件。
HttpRequest httpRequest = HttpRequest
.post("http://srv:8080/api/dlapp/add-file-entry")
.form(
"title", "test",
"description", "Upload test",
"file", new File("d:\a.jpg.zip"),
"file", new File("d:\b.jpg.zip")
);
HttpResponse httpResponse = httpRequest.send();
这是正确的代码。您只需添加文件参数:
HttpRequest httpRequest = HttpRequest.post("localhost:8173/echo")
.form(
"title", "test",
"description", "Upload test",
"file1", temp1,
"file2", temp2
);
仅此而已。有 the testcase 可以检查这一点。
最简单的检查方法是启动,例如Wireshark 在您的本地机器上并简单地检查请求;其中必须有两个文件块。
您的服务器端是否可能出于某种原因不接受文件?
您使用的是最新版本(v5.0.x)吗?
p.s。如果您要发送两个文件,请使用两个不同的参数名称(例如 file1
、file2
)。
如何使用 jodd HTTP 在同一请求中上传多个文件?
我试过类似下面的方法,但只发布了第一个文件。
HttpRequest httpRequest = HttpRequest
.post("http://srv:8080/api/dlapp/add-file-entry")
.form(
"title", "test",
"description", "Upload test",
"file", new File("d:\a.jpg.zip"),
"file", new File("d:\b.jpg.zip")
);
HttpResponse httpResponse = httpRequest.send();
这是正确的代码。您只需添加文件参数:
HttpRequest httpRequest = HttpRequest.post("localhost:8173/echo")
.form(
"title", "test",
"description", "Upload test",
"file1", temp1,
"file2", temp2
);
仅此而已。有 the testcase 可以检查这一点。
最简单的检查方法是启动,例如Wireshark 在您的本地机器上并简单地检查请求;其中必须有两个文件块。
您的服务器端是否可能出于某种原因不接受文件?
您使用的是最新版本(v5.0.x)吗?
p.s。如果您要发送两个文件,请使用两个不同的参数名称(例如 file1
、file2
)。