- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在java play应用程序中,我公开了文件的Put请求,并且我想在wsClient的另一个请求中使用此FilePart:
public CompletionStage<String> upload() {
Http.RequestBody body = request().body();
Http.MultipartFormData formData = body.asMultipartFormData();
Http.MultipartFormData.FilePart<File> file = formData.getFile("file");
return wsClient.url("fake")
.setContentType("multipart/form-data")
.post(Source.single(b))
.thenApplyAsync(wsResponse -> {
return wsResponse.getBody();
})
.exceptionally(throwable -> throwable.getMessage());
}
我得到了响应:“java.lang.UnsupportedOperationException:不支持的部件类”
感谢您的帮助
最佳答案
此帖子端点需要以下类型的正文:
Source<? super Http.MultipartFormData.Part<Source<ByteString, ?>>, ?>
可以通过以下方式从表单部件列表构建:
List<Http.MultipartFormData.Part> partList = new ArrayList<>();
Source<ByteString, ?> file = FileIO.fromFile(filePart.getFile());
Http.MultipartFormData.FilePart<Source<ByteString, ?>> filePart = new Http.MultipartFormData.FilePart<>(file.getKey(), file.getFilename(), filePart.getContentType(), file);
partList.add(filePart);
然后,您可以使用以下命令将其作为帖子正文提供:
.post(Source.from(Collections.unmodifiableList(partList)))
关于java - Play 应用程序 |如何将 FilePart 传递给其他请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59845231/
我需要使用 WebClient 将 RestController 中收到的 FilePart 发送到 API, 我怎样才能做到这一点? 找到一个示例,将图像保存到磁盘。 private static
在java play应用程序中,我公开了文件的Put请求,并且我想在wsClient的另一个请求中使用此FilePart: public CompletionStage upload() {
在 MATLAB 中,有一个名为 fileparts 的好函数,它获取完整文件路径并将其解析为路径、文件名(不带扩展名)和扩展名,如文档中的以下示例所示: file = 'H:\user4\matla
我正在尝试使用 Scala 和 Play 2.4.6 通过多部分表单数据发送文件。 def sendFile(file: FilePart[TemporaryFile]): Option[Futu
我有从网络表单接收和上传文件的 Controller 方法。如何从 FilePart 中提取字节数组并将其保存到数据库? 我可以通过使用 FilePart.transferTo() 将 FilePar
使用 WinSCP 的 .NET 程序集上传文件。 OperationResultBase.Check() 抛出以下错误: WinSCP.SessionRemoteException: Transfe
我是一名优秀的程序员,十分优秀!