rest-full java-8发送文件

s5a0g9ez  于 2021-06-29  发布在  Java
关注(0)|答案(0)|浏览(144)

我在控制器中收到上传的文件,我想将它上传到另一个通过web服务的数据库。
web服务资源:

@Path("/upload")
public class UploadResource {

    @POST
    @Path("/test")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Produces(MediaType.MULTIPART_FORM_DATA)
    public Response testUpload(Multipart multipart) {
        return Response.status(Response.Status.OK).entity(null).build();
    }   

}

控制器核心功能:

RestTemplate restTemplate = new RestTemplate();
    restTemplate.setErrorHandler(this.responseHandler);

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.MULTIPART_FORM_DATA);
    headers.setAccept(Collections.singletonList(MediaType.MULTIPART_FORM_DATA));

如何上传文件并在web服务中读取?
谢谢您。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题