如何用基于wink的restful服务传输文件流

如何用基于wink的restful服务传输文件流,第1张

服务器端程序:

@POST

@Path("/橘尘getZip")

@Produces("application/zip")

public Response getZip(String message) throws FileNotFoundException {

FileInputStream fis = new FileInputStream(new File("E:/src/1.zip"))

Response.ResponseBuilder responseBuilder = null

Response response = null

responseBuilder = Response.ok(fis, MediaType.APPLICATION_OCTET_STREAM_TYPE)

responseBuilder.type(MediaType.APPLICATION_OCTET_STREAM_TYPE)

response = responseBuilder.header("content-disposition", "inlinefilename= file.zip").build()

return response

}

客户端程序圆行禅:

RestClient restClient = new RestClient()

Resource resource = restClient.resource("your url")

final ClientResponse response = resource.post(message)

System.out.println("服务器返回状态: " + response.getStatusCode())

InputStream is = response.getEntity(new EntityType<InputStream>(){})

System.out.println("服务器返带升回文件大小: " + is.available())

不太清楚你写这个借口的目的是什么,一般我们做上传和侍都是前端通过控件上传后得到路径,然后调用一个方法将路径保存就可以了。你这个借口的目的是什么?

先调用接口获得路径是保存路径不一样的森蠢情况才这样做的。如果上传的路径是一样此棚陪的就没有那个必要再去调用一次了


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/tougao/12360509.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存