在REST Web服务中上载数据方法 [英] Upload data method in REST web service

查看:153
本文介绍了在REST Web服务中上载数据方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何在RESTful Web服务中编写POST方法来使用java上传数据?
我发现smartupload和commons.upload仅适用于网页。

Do anyone know how can I write POST method in RESTful web service to upload data using java ? I found that smartupload and commons.upload are just for web page.

推荐答案

你可以使用一些JAX-RS库,就像 Apache Wink 一样,所以你可以写这样的东西:

You can use some JAX-RS library, like Apache Wink, so you can write something like this:

@Path("/upload")
class UploadResource {

    @POST
    @Consumes(MediaType.APPLICATION_OCTET_STREAM)
    public Response upload(byte[] input) {
        // store input somewhere
        return Response.ok().build();
    }

}

所以你会收到你的文件是字节[] 。你也可以收到InputStream:

So you will receieve your file is byte[]. You can also receive as InputStream:

@Path("/upload")
class UploadResource {

    @POST
    @Consumes(MediaType.APPLICATION_OCTET_STREAM)
    public Response upload(InputStream input) {
        // store input somewhere
        return Response.ok().build();
    }

}

这篇关于在REST Web服务中上载数据方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆